As you can tell I'm trying to put together a very simple 3d engine. I'm writing it in javascript. I think it's likely that there is an error in the formula, but for the life of me I can't find it. So now I'm thinking there might be something else I haven't considered yet. The error occurs on line 21 (dx = Math.cos.....)
Here is the relevant part of my code:
// Camera Position in x,y,z
var c = [ 0,0,0 ];
// Viewer position [x,y,z]
var v = [ 0,0,0 ];
// Angle of view [x, y, z]
var a = [ 0.01, 0.01, 0.01 ];
var point = [ 0,0, 50 ];
dx = Math.cos(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0])) - Math.sin(a[1])(point[2] - c[2]);
dy = Math.sin(a[0])(Math.cos(a[1])(point[2] - c[2]) + Math.sin(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0]))) + Math.cos(a[0])(Math.cos(a[2])(point[1] - c[1]) - Math.sin(a[2])(point[0] - c[0]));
dz = Math.cos(a[0])(Math.cos(a[1])(point[2] - c[2]) + Math.sin(a[1])(Math.sin(a[2])(point[1] - c[1]) + Math.cos(a[2])(point[0] - c[0]))) - Math.sin(a[0])(Math.cos(a[2])(point[1] - c[1]) - Math.sin(a[2])(point[0] - c[0]));
bx = (dx - v[0])(v[2]/dz);
by = (dy - v[1])(v[2]/dz);
You need to use * to multiply:
dx = Math.cos(a[1])*(Math.sin(a[2])*(point[1] - c[1]) ... etc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With