WIP kegel v kalibraciji, rotacija skatle v schemu

kegel
Jurij Podgoršek 2022-11-27 09:45:23 +01:00
parent d784c6dd81
commit f1b5b69850
3 changed files with 107 additions and 22 deletions

View File

@ -185,11 +185,11 @@ function addObj(w, h) {
color: col
});
var geo = new THREE.BufferGeometry();
var offset = h / 2;
// Karo
var geo = new THREE.BufferGeometry();
var vertices = new Float32Array([
-offset, 0, 0, 0, offset, 0,
-offset, 0, 0, 0, -offset, 0,

View File

@ -1,12 +1,12 @@
(use-modules (chickadee)
(chickadee graphics color)
(chickadee graphics sprite)
(chickadee graphics text)
(chickadee graphics path)
(chickadee graphics pbr)
(chickadee graphics mesh)
(chickadee graphics model)
(chickadee graphics light)
(chickadee graphics skybox)
(chickadee math vector)
(chickadee math rect)
(system repl coop-server))
(define repl (spawn-coop-repl-server))
@ -32,13 +32,22 @@
(define rotZ 0)
(define (obj-anim dt)
(set! rotX (+ rotX dt))
(set! rotY (+ rotY (/ dt 2)))
(set! rotZ (+ rotZ (/ dt 3)))
(set! rotX (+ rotX (/ dt 2)))
(set! rotY (+ rotY (/ dt 1)))
(set! rotZ (+ rotZ (/ dt 1.5)))
(matrix4-rotate-x! model-matrix rotX)
(matrix4-rotate-y! model-matrix rotY)
(matrix4-rotate-z! model-matrix rotZ))
(matrix4-copy! (matrix4* (matrix4-scale stevec)
(matrix4-rotate-x rotX)
(matrix4-rotate-y rotY)
(matrix4-rotate-z rotZ))
model-matrix)
;(matrix4-scale! model-matrix stevec)
;(matrix4-mult! model-matrix model-matrix (matrix4-scale stevec))
;(matrix4-rotate-x! model-matrix rotX)
;(matrix4-rotate-y! model-matrix rotY)
;(matrix4-rotate-z! model-matrix rotZ))
)
(define (key-press key modifiers repeat?)
(cond
@ -53,15 +62,17 @@
(set! stevec 1))
(define camera-position (vec3 0.0 0.0 3.0))
(define projection (perspective-projection (/ pi 3.0) (/ 4.0 3.0) 0.1 5.0))
(define projection (perspective-projection (/ pi 3.0) (/ 4.0 3.0) 0.1 10.0))
(define view-matrix (make-identity-matrix4))
(define model-matrix (make-identity-matrix4))
(define position (vec3 0.0 0.0 -4.0))
(define (ustvari-tla)
(make-plane 500 500 (make-pbr-material #:base-color-factor (vec3 1.0 0.5 0))))
(define (ustvari-objekt)
(let ;((velikost (* 1000 (log stevec))))
((velikost (/ stevec 1000.0))
(barva (vec3 0.2 0.8 0.4)))
(let ((velikost (/ stevec 2000.0))
(barva (vec3 0.2 0.8 0.4)))
(make-cube velikost
(make-pbr-material #:base-color-factor barva))
@ -72,19 +83,39 @@
(define obj #f)
(define (ustvari-nebo)
(let ((face (list
(u32vector #x12345678
#x87654321
#x12345678
#x87654321)
4
4)))
(make-skybox
(make-cube-map (make-list 6 face)))))
(define (draw alpha)
(with-projection
projection
(draw-mesh (ustvari-objekt)
(draw-mesh obj
#:model-matrix model-matrix
#:view-matrix view-matrix
#:camera-position position)))
#:camera-position position
#:lights (list (ustvari-luc))
#:skybox (ustvari-nebo))))
;; :( ne dela?
(define (ustvari-luc)
(make-directional-light
#:direction (vec3 1 1 1)
#:color white
#:intensity 10))
(define (load)
;; Moramo pogledat model
(poglej)
(reset-stevec)
(ustvari-luc)
(set! obj (ustvari-objekt)))
(run-game

66
test.js
View File

@ -10,11 +10,6 @@ var odmik_kamere = 100;
// Vidni kot
var FOV = 140;
// Sirina in visina test objekta
var width = 25;
var height = 150;
var depth = 50;
// Parametri rotacije (euler)
var rotacijaX = 0.000;
var rotacijaY = 0.000;
@ -44,12 +39,66 @@ renderer.setClearColor(0xFFFFFF, 1);
var skupina = new THREE.Group();
// Dodaj test skatlo
var geo = new THREE.BoxGeometry(width, height, depth);
// Sirina in visina test objekta
var width = 100;
var height = 250;
var depth = 50;
//var geo = new THREE.BoxGeometry(width, height, depth);
var radialnihSegmentov = 32;
var visinskihSegmentov = 32;
//var geo = new THREE.CylinderGeometry(width, width, height, radialnihSegmentov, visinskihSegmentov);
var geo = new THREE.BufferGeometry();
var offset = width;
var polozaji = [];
// spodnji krog
for (var s = 0; s < radialnihSegmentov; s++) {
polozaji.push(
0,
0,
0,
Math.sin(2 * Math.PI * s / radialnihSegmentov) * width,
Math.cos(2 * Math.PI * s / radialnihSegmentov) * width,
0,
Math.sin(2 * Math.PI * (s + 1) / radialnihSegmentov) * width,
Math.cos(2 * Math.PI * (s + 1) / radialnihSegmentov) * width,
0
);
}
console.log(polozaji);
// vmesni segmenti
/*
for (var h = 0; h < visinskihSegmentov; h++) {
for (var s = 0; s <= radialnihSegmentov; s++) {
polozaji.push(
Math.sin(2 * Math.PI * s / radialnihSegmentov),
Math.cos(2 * Math.PI * s / radialnihSegmentov),
h * height / visinskihSegmentov
);
}
}
*/
var vertices = new Float32Array(polozaji);
geo.setAttribute('position', new THREE.BufferAttribute(vertices, 3));
window.geo = geo;
// Deformiramo za kegel
for (var n = 0; n < radialnihSegmentov; n += 1) {
geo.attributes.position.array[1 + n * 3] += 10;
geo.attributes.position.array[1 + n * 3 + 1] += 30;
geo.attributes.position.needsUpdate = true
}
var mat = new THREE.MeshBasicMaterial({
color: 0xff00ff,
wireframe: true
});
//var mat = new THREE.LineBasicMaterial({ color: 0xff00ff });
var cube = new THREE.Mesh(geo, mat);
//var cube = new THREE.Line(geo, mat, THREE.LineSegments);
skupina.add(cube);
@ -92,6 +141,11 @@ function objAnim() {
AX.scale.x = accX / 1000;
});
// rotiramo skupino da se vidi
skupina.rotation.x += 0.003;
skupina.rotation.y += 0.005;
skupina.rotation.z += 0.007;
// Drzimo vse stiri gumbe (reset)? - kalibracija!
if ((keysPressed[0] + keysPressed[1] + keysPressed[2] + keysPressed[3]) === 4) {
if (!reset) {