0
votes

I've been working on a little space simulator demo using three.js and flightcontrols.js (an example that ships with three.js)

The demo is viewable at - http://www.zacharycarter.com/PrivateerRedux/demo.html

The control scheme is pretty simple - the mouse controls the camera and you left click to fire a projectile.

I'm having a little bit of trouble with how I'm spawning my projectiles. Currently I'm setting their rotation to the same rotation of my camera which I believe is what is causing my problems.

You'll notice that as you rotate the camera around the game world, and continue firing projectiles, that the position and orientation of the projectiles quickly becomes whacky.

I'm using quaternions to represent my camera's rotation but I also derrive the Euler angles from the quaternion before setting my projectiles rotation to match that of my cameras.

Any ideas as to what I'm doing wrong here? I have a feeling I need to figure out a constant front facing rotation from my camera rotation but I'm not quite sure how to do that.

Thanks!

1
If I remember right, there are about 20 different definitions of 'Euler angles'. Are you sure you are using the right one? I would recommend dropping Euler angles altogether and using only transformation matrices and/or quaternions. - Alptigin Jalayr
Three.js has a method built into it called setEulerFromQuaternion. This method is called in the control library I am using. I'm not sure what the underlying implementation is, but it still doesn't answer my question as to what I'm doing wrong here, quaternions or not... - Zachary Carter
Btw, I am using google chrome on windows, and the demo does not work. I am unable to see projectiles on performing left clicks. - Alptigin Jalayr
Please try moving your mouse downwards, so that the camera view rotates downwards. The projectiles are just out of view when the app first loads. - Zachary Carter
I moved the location projectiles are spawned at up so they'll be plainly visible when the demo is launched. Also I've updated the projectile rotation to use quaternions but something is still off... - Zachary Carter

1 Answers

1
votes

If I understand this correctly, I think your problem is that you're applying world transformations and local transformations (i.e rotation in world space to have bullets fly in the right direction and rotation of bullets around the bullets' local axes) incorrectly. It seems they're all being applied in the same space.

Instead of writing up a whole new example, however, I'll leave it to the old, trusty internet to hand us some guidance on the issue using the common example of a solar system.

This might enlighten you:

http://docs.techsoft3d.com/visualize/3df/latest/Hoops3DGS/prog_guide/03_3_viewing_modelling_matrices.html (have a look at figure 3.3.2.b)

...and here's an OpenGL example demonstrating the same thing:

http://www.codemiles.com/c-opengl-examples/solar-system-transformations-t7292.html

There's the theory anyway, hope that helps!