Move in view direction when pressing 'w'
This commit is contained in:
parent
2200b54b21
commit
cf77804e5e
@ -84,24 +84,46 @@ function main() {
|
|||||||
|
|
||||||
function move(e)
|
function move(e)
|
||||||
{
|
{
|
||||||
if (e.keyCode == '87') //w
|
if (false) {
|
||||||
{
|
if (e.keyCode == '87') //w
|
||||||
eye[2] = eye[2] - 0.5;
|
{
|
||||||
target[2] = target[2] - 0.5;
|
eye[2] = eye[2] - 0.5;
|
||||||
} else if (e.keyCode == '83') //s
|
target[2] = target[2] - 0.5;
|
||||||
{
|
} else if (e.keyCode == '83') //s
|
||||||
eye[2] = eye[2] + 0.5;
|
{
|
||||||
target[2] = target[2] + 0.5;
|
eye[2] = eye[2] + 0.5;
|
||||||
} else if (e.keyCode == '65') //a
|
target[2] = target[2] + 0.5;
|
||||||
{
|
} else if (e.keyCode == '65') //a
|
||||||
eye[0] = eye[0] - 0.5;
|
{
|
||||||
target[0] = target[0] - 0.5;
|
eye[0] = eye[0] - 0.5;
|
||||||
} else if (e.keyCode == '68') //d
|
target[0] = target[0] - 0.5;
|
||||||
{
|
} else if (e.keyCode == '68') //d
|
||||||
eye[0] = eye[0] + 0.5;
|
{
|
||||||
target[0] = target[0] + 0.5;
|
eye[0] = eye[0] + 0.5;
|
||||||
|
target[0] = target[0] + 0.5;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (true) {
|
||||||
|
let distance = Math.sqrt((target[0]-eye[0])**2 + (target[2]-eye[2])**2)
|
||||||
|
let moveX = ((target[0]-eye[0])/distance)/2;
|
||||||
|
let moveZ = ((target[2]-eye[2])/distance)/2;
|
||||||
|
|
||||||
|
if (e.keyCode == "87") { // w
|
||||||
|
eye[0] = eye[0] + moveX;
|
||||||
|
eye[2] = eye[2] + moveZ;
|
||||||
|
target[0] = target[0] + moveX;
|
||||||
|
target[2] = target[2] + moveZ;
|
||||||
|
} else if (e.keyCode == "65") { // a
|
||||||
|
console.log("key not implemented")
|
||||||
|
} else if (e.keyCode == "83") { // s
|
||||||
|
console.log("key not implemented")
|
||||||
|
} else if (e.keyCode == "68") { // d
|
||||||
|
console.log("key not implemented")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log(eye[0], eye[2]);
|
||||||
//set the viewMatrix
|
//set the viewMatrix
|
||||||
const viewLoc = gl.getUniformLocation(program, "viewMatrix");
|
const viewLoc = gl.getUniformLocation(program, "viewMatrix");
|
||||||
mat4.lookAt(viewMatrix, eye, target, up);
|
mat4.lookAt(viewMatrix, eye, target, up);
|
||||||
|
Loading…
Reference in New Issue
Block a user