Skip to content

Commit

Permalink
Temporarily implified rot4.js for debugging.
Browse files Browse the repository at this point in the history
Changed avatarMatrixForward to avatarMatrixInverse in various places in SystemHandler.js
More experiments with hypercube in week10.js
  • Loading branch information
Ken Perlin committed Jan 19, 2020
1 parent 5ba15db commit 24b331e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 13 deletions.
2 changes: 1 addition & 1 deletion lib/primitive/rot4.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ let Rot4 = function() {
a = Math.acos(Math.min(1,norm(P0))),
b = Math.acos(Math.min(1,norm(P1))),
c1 = Math.cos(b - a),
s1 = (b < a ? 1 : -1) * Math.sqrt(1 - c1 * c1),
s1 = (b > a ? 1 : -1) * Math.sqrt(1 - c1 * c1),
A = [ X[0],X[1],X[2],0, Y[0],Y[1],Y[2],0, Z[0],Z[1],Z[2],0, 0,0,0,1 ],
AI = [ X[0],Y[0],Z[0],0, X[1],Y[1],Z[1],0, X[2],Y[2],Z[2],0, 0,0,0,1 ],
B = [ c0,s0,0,0, -s0,c0,0,0, 0,0,1,0, 0,0,0,1 ],
Expand Down
15 changes: 12 additions & 3 deletions locallib/SystemHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,17 @@ export function pollAvatarData() {
user: MR.playerid,
state: {
mode: MR.UserType.vr,
pos: CG.matrixTransform(MR.avatarMatrixForward, headsetPos),

//pos: CG.matrixTransform(MR.avatarMatrixForward, headsetPos),
pos: CG.matrixTransform(MR.avatarMatrixInverse, headsetPos),

rot: headsetRot,
controllers: {
left: {
pos: CG.matrixTransform(MR.avatarMatrixForward, [

//pos: CG.matrixTransform(MR.avatarMatrixForward, [
pos: CG.matrixTransform(MR.avatarMatrixInverse, [

controllerLeftPos[0],
controllerLeftPos[1],
controllerLeftPos[2]
Expand All @@ -127,7 +133,10 @@ export function pollAvatarData() {
analogy: controllerLeft.axes[1]
},
right: {
pos: CG.matrixTransform(MR.avatarMatrixForward, [

//pos: CG.matrixTransform(MR.avatarMatrixForward, [
pos: CG.matrixTransform(MR.avatarMatrixInverse, [

controllerRightPos[0],
controllerRightPos[1],
controllerRightPos[2]
Expand Down
54 changes: 45 additions & 9 deletions worlds/week10/week10.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import {Lock} from "../../lib/core/lock.js";


/*--------------------------------------------------------------------------------
The proportions below just happen to match the dimensions of my physical space
Expand All @@ -28,7 +27,7 @@ const TABLE_WIDTH = inchesToMeters( 60);
const TABLE_THICKNESS = inchesToMeters( 11/8);
const LEG_THICKNESS = inchesToMeters( 2.5);

const HYPERCUBE_POSITION = [0,EYE_HEIGHT,-1];
const HYPERCUBE_POSITION = [0,EYE_HEIGHT,-.5];
const HYPERCUBE_SCALE = 0.2;

let enableModeler = true;
Expand Down Expand Up @@ -729,6 +728,24 @@ function myDraw(t, projMat, viewMat, state, eyeIdx, isMiniature) {
-----------------------------------------------------------------*/

let getControllerBeamPoint = (C, t) => {
let P = state.position;
m.save();
m.translate(-P[0],-P[1],-P[2]);
m.rotateY(-state.turnAngle);
m.rotateX(-state.tiltAngle);
m.multiply(state.avatarMatrixForward);

m.translate(C.position());
m.rotateQ(C.orientation());
m.translate(0,.02,-.005);
m.rotateX(.75);
m.translate(0,0,-.0095 - t);
P = m.transform([0,0,0]);
m.restore();
return P;
}

let drawController = (pos, rot, hand, isPressed) => {
m.save();
m.translate(pos);
Expand Down Expand Up @@ -813,6 +830,23 @@ function myDraw(t, projMat, viewMat, state, eyeIdx, isMiniature) {
m.restore();
}

let bounce = t => {
t = (2 * t) % 2;
t = t < 1 ? t : 2 - t;
return 1 - t * t;
}

// SEE IF WE HAVE A CORRECT UNDERSTANDING OF THE CONTROLLER TIP POSITION.

if (input.LC) {
m.save();
m.translate(getControllerBeamPoint(input.LC, .3 * bounce(state.time)));
m.rotateY(state.time);
m.scale(.021);
drawShape(CG.sphere, [2,2,2]);
m.restore();
}

/*-----------------------------------------------------------------
This is where I draw the objects that have been created.
Expand Down Expand Up @@ -982,22 +1016,25 @@ function myDraw(t, projMat, viewMat, state, eyeIdx, isMiniature) {
}
}

/*
// HYPERCUBE IN A 4D TRACKBALL

{
let isControllerInHypercube = false;
if (input.LC && input.LC.isDown()) {
let D = CG.scale(CG.subtract(input.LC.tip(), HYPERCUBE_POSITION), 1 / HYPERCUBE_SCALE);
if (norm(D) > 1) {
if (CG.norm(D) < 1) {
isControllerInHypercube = true;
if (input.D !== undefined)
rot4.rotate(input.D, D);
input.D = D;
input.D = D.slice();
}
else
delete input.D;
}

rot4.rotate([0,-.5,0],[0,-.499,0]);
if (isControllerInHypercube)
rot4.rotate([-.101,0,.9],[-.1,0,.9]);

let U = rot4.hypercube();
let H = rot4.transformedHypercube();

Expand All @@ -1013,14 +1050,13 @@ function myDraw(t, projMat, viewMat, state, eyeIdx, isMiniature) {
m.scale(s);
s = Math.pow(s + .1, 3);
m.translate([v[0],v[1],v[2]]).scale(.1);
drawShape(CG.cube, [s * (.5 + .4 * u[0]),
drawShape(CG.cube, [1,1,1]/*[s * (.5 + .4 * u[0]),
s * (.5 + .4 * u[1]),
s * (.5 + .4 * u[2])]);
s * (.5 + .4 * u[2])]*/);
m.restore();
}
m.restore();
}
*/
}

function onEndFrame(t, state) {
Expand Down

0 comments on commit 24b331e

Please sign in to comment.