# Finding the right vector

• 05-15-2002
VirtualAce
Finding the right vector
I'm working on a starfield right now. How do you always make the stars come towards you while moving the ship through 3D space at any angle?

Just using the stars as an effect and not really part of the world does not look right when you turn the ship. The stars should react somewhat to your moves.

Could I treat the stars like a 3D cube? After all I have a finite amount of stars within a section of 3D space. Then perhaps I could use backface culling to find out which side faces me, get the surface normal of it, and move the stars along that normal. Will that work? It's much faster than calculating the actual normal from the star to my ship for every star.

Also, how do I make these stars loop in 3D space. Since it is a finite cube of stars, it is possible to fly out of the starfield and into nothingness. Again do I take the normal of the face that my ship is heading and then reset the stars along that normal a set distance to "push" them into the distance along my normal vector?

For instance:

my ship --->

the normal of my ship's vector is the plane that my ship is in. Draw a box around the front of my ship's nose, like a big shield on the front or something. If i take the surface normal of that box, I will get my direction vector.

Please, I need help. I've looked at the web and found only simple starfields with no motion relative to an actual 3D universe.
• 05-17-2002
*
Actually, I would recommend just using a starfield bitmap that scrolls in the appropriate directions based on how your ship moves. Stars are so far away (almost all of them have turned out to be galaxies, instead) that someone in a ship would never see more than that movement anyway.

If you still want some 3D stars, then put 20 or so on the screen as the layer in front of the starfield bitmap, and move those 20 as you would any other 3D object in your 3D world.
• 05-19-2002
Coder
For calculating the right & up vectors of any plane, check this link on flipcode : http://www.flipcode.com/tutorials/tut_decals.shtml
It's about decaling, and it's got a section about what you want.
• 05-19-2002
Coder
After reading your post throughly, and realizing what you actually want to do, I thought of a solution :
What you want to do is, display the starts coming towards the ship regardless of the ship's orientation.

Note : I've not tried any of the following, but it seems right to me :) Ofcourse there might be stupid mistakes that I haven't noticed.

The view transformation is what makes an object's appearance depend on the camera's orientation ( view vector orientation ).
This trasnformation does the following in order :
a) Translates the vertices with negative the camera's position.
b) Rotates the vertices with negative the camera's angles with the 3 axis

If you drop the rotation part, then all objects will always be facing the camera. In order to specify a distance between the stars & your camera, make a special view matrix that only does translation ( to translate stars away from the near plane )

Assuming a left hand system where Z increases into the screen, you can set the Z value of the translation vector to a +ve value ( to translate stars away from the near plane )

Note also that the "velocity direction vector" is always (0,0,-1) ( Left hand system, z increases into the screen )

By the way, about treating the stars as a 3D cube : I believe it'd be better if you treat them as a sphere ( although that'll require that you calculate a direction vector & a position for each star. This can be done fast by some Sine & Cosine calculations, however )