Finding the right vector

This is a discussion on Finding the right vector within the Game Programming forums, part of the General Programming Boards category; I'm working on a starfield right now. How do you always make the stars come towards you while moving the ...

  1. #1
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,598

    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.

  2. #2
    *
    Guest
    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.

  3. #3
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    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.
    Muhammad Haggag

  4. #4
    Registered User Coder's Avatar
    Join Date
    Aug 2001
    Location
    Cairo, Egypt
    Posts
    128
    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 )
    Muhammad Haggag

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. can some one please tell me the cause of the error ?
    By broli86 in forum C Programming
    Replies: 8
    Last Post: 06-26-2008, 09:36 PM
  2. syntax help?
    By scoobygoo in forum C++ Programming
    Replies: 1
    Last Post: 08-07-2007, 11:38 AM
  3. Vector class
    By Desolation in forum C++ Programming
    Replies: 2
    Last Post: 05-12-2007, 06:44 PM
  4. Need some help/advise for Public/Private classes
    By nirali35 in forum C++ Programming
    Replies: 8
    Last Post: 09-23-2006, 01:34 PM
  5. Certain functions
    By Lurker in forum C++ Programming
    Replies: 3
    Last Post: 12-26-2003, 01:26 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21