skycraft: can walk around the earth
This commit is contained in:
parent
8f43cf3a01
commit
be36b310b4
@ -312,10 +312,12 @@ export function draw(context) {
|
|||||||
|
|
||||||
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
gl.clear(gl.COLOR_BUFFER_BIT | gl.DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
|
const thirdPerson = context.landed ? se3.identity() : se3.translation(0, 1, 4);
|
||||||
|
|
||||||
const playerView = [
|
const playerView = [
|
||||||
player.tf, // player position & orientation
|
player.tf, // player position & orientation
|
||||||
camera.tf, // camera orientation relative to player
|
camera.tf, // camera orientation relative to player
|
||||||
se3.translation(0, 1, 4), // step back from the player
|
thirdPerson,
|
||||||
];
|
];
|
||||||
if (context.landed) {
|
if (context.landed) {
|
||||||
const body = context.landedBody;
|
const body = context.landedBody;
|
||||||
|
@ -173,10 +173,20 @@ function initUiListeners(canvas: HTMLCanvasElement, context) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
const moveListener = e => {
|
const moveListener = e => {
|
||||||
// context.camera.orientation[0] -= e.movementY / 500;
|
const cam = context.camera;
|
||||||
// context.camera.orientation[1] -= e.movementX / 500;
|
if (context.landed) {
|
||||||
context.camera.tf =[
|
cam.orientation[1] -= e.movementX / 500;
|
||||||
context.camera.tf,
|
cam.orientation[0] -= e.movementY / 500;
|
||||||
|
cam.tf = [
|
||||||
|
se3.roty(cam.orientation[1]),
|
||||||
|
se3.rotx(cam.orientation[0]),
|
||||||
|
].reduce(se3.product);
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
cam.tf =[
|
||||||
|
cam.tf,
|
||||||
se3.roty(-e.movementX / 500),
|
se3.roty(-e.movementX / 500),
|
||||||
se3.rotx(-e.movementY / 500),
|
se3.rotx(-e.movementY / 500),
|
||||||
].reduce(se3.product);
|
].reduce(se3.product);
|
||||||
@ -252,21 +262,25 @@ function moveOnGround(context, forward, right) {
|
|||||||
se3.orientationOnly(context.player.tf),
|
se3.orientationOnly(context.player.tf),
|
||||||
context.camera.tf,
|
context.camera.tf,
|
||||||
);
|
);
|
||||||
const dir = [right, 0, -forward, 0];
|
const dir = se3.apply(tf, [right, 0, -forward, 0]);
|
||||||
if (context.flying) {
|
if (context.flying) {
|
||||||
context.player.tf = [
|
context.player.tf = [
|
||||||
context.player.tf,
|
|
||||||
se3.translation(...dir),
|
se3.translation(...dir),
|
||||||
|
context.player.tf,
|
||||||
].reduce(se3.product);
|
].reduce(se3.product);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const dv = linalg.scale(se3.apply(tf, dir), 10);
|
const dv = linalg.scale(dir, 10);
|
||||||
|
|
||||||
const maxSpeed = 8;
|
const maxSpeed = 8;
|
||||||
const airMovement = 0.08;
|
const airMovement = 0.08;
|
||||||
|
|
||||||
if (context.isOnGround) {
|
if (context.isOnGround) {
|
||||||
context.player.velocity = dv;
|
const up = upDirection(context);
|
||||||
|
const vertical = linalg.dot(dv, up);
|
||||||
|
const horizontal = linalg.diff(dv, linalg.scale(up, vertical));
|
||||||
|
context.player.velocity = horizontal;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -466,6 +480,11 @@ function effectiveGravity(position: number[], rootBody: Body) : number[] {
|
|||||||
return acceleration;
|
return acceleration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function upDirection(context) {
|
||||||
|
const gravity = landedGravity(context);
|
||||||
|
return linalg.normalize(linalg.scale(gravity, -1));
|
||||||
|
}
|
||||||
|
|
||||||
function landedGravity(context) {
|
function landedGravity(context) {
|
||||||
// just clamp "down" to one of our six directions
|
// just clamp "down" to one of our six directions
|
||||||
const pos = context.player.position;
|
const pos = context.player.position;
|
||||||
@ -558,6 +577,11 @@ function updateLandedPhysics(context, dt) {
|
|||||||
}
|
}
|
||||||
context.isOnGround = isOnGround;
|
context.isOnGround = isOnGround;
|
||||||
context.player.tf = se3.setPosition(context.player.tf, newPos);
|
context.player.tf = se3.setPosition(context.player.tf, newPos);
|
||||||
|
|
||||||
|
// up is up
|
||||||
|
const p = context.player;
|
||||||
|
const currentOrientation = slerp(p.tf, alignUp(p.tf, upDirection(context)), 0.1);
|
||||||
|
p.tf = se3.setOrientation(p.tf, currentOrientation);
|
||||||
}
|
}
|
||||||
|
|
||||||
function updatePhysics(time: number, context) {
|
function updatePhysics(time: number, context) {
|
||||||
|
Loading…
Reference in New Issue
Block a user