Thread: Update screenie with billboards

  1. #16
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    It's a lot easier to just keep track of the *tangent vectors* in order to do billboards. I.e, instead of doing all of that matrix stuff for every billboard, you just rotate the local coordinate system by the current angles of the view vector. Then, you just specify the coordinates of a given billboard in terms of magnitudes of the tangent vectors.

    Ultimately, this is MUCH faster than applying the matrix terms you have specified (assuming you have a lot of billboarded objects as you do).

    Also, this is how most graphics apis actually rotate the scene...they simply rotate the coordinate system by using a matrix, but then the verticies are just specified in terms of the unit vectors...big speed boost.

  2. #17
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I've looked at several billboarding source code snippets in books and the SDK and all of them use the view matrix or D3DXMatrixRotationY(). Either way they are still multiplying.

    My final project will have the matrix billboard stored in the camera class. The Billboard class will then simply retrieve the billboard matrix, alter members ._41,._42, and ._43 for translation of the billboard, sort the billboards from back to front, cull the unneeded billboards, and draw all billboards in the scene with their current texture.

    Keep in mind the math will only be done once per frame, not once per billboard.

    This can be done also with animated billboards. Animation comes from an animation controller class that simply tracks a timer (another class) and when the current timer is up for the frame, it switches texture pointers to the next one in the list. The actual billboard or sprite does not carry the animation data, the class carries a pointer to the animation controller class. In this way all animations are separate from the sprites. So all that needs to be done is to render the sprite, billboard, or what have you with the correct texture and the correct time based on frame_time.

    Also, this is how most graphics apis actually rotate the scene...they simply rotate the coordinate system by using a matrix, but then the verticies are just specified in terms of the unit vectors...big speed boost.
    Suspicious at best. I suppose you could scale your model vertices every frame to get the desired size or you could create the model with the desired size. Either way you still cannot render the final model w/o doing something to it. I do not store the model's as unit vectors so that I do not have to scale them every time I want to use them. My coordinate system is rotated by matrices in the camera class and quite frankly I have no idea how you would call this a speed boost since this is what has to be done to get the desired results.

    I know how D3D rotates the scene and yes it is by using matrices, which from my source code you can see I'm using matrices too. Where do you think the view matrix came from?

    All that has to be done in each of my classes is this:

    1. Rotate the object in model space.
    2. Translate the object in world space
    3. Rotate the object in world space, if need be.

    Code:
    ...
    void Object::Render(float frame_time)
    {
      //Model rotation
      D3DXMATRIX mrot;
      D3DXMatrixRotation(&mrot,Rotation.x,Rotation.y,Rotation.z);
     
      //World rotation if needed?
     
      //Translate
      mrot._41=Position.x;
      mrot._42=Position.y;
      mrot._43=Position.z;
     
      Device->SetTransform(D3DTS_WORLD,&mrot);
     
      ..Render
    }
    I wish I could get rid of the Transform portion because switching transforms in D3D is costly, but the only other way would be to take the view matrix and step down one level to the world matrix, alter the correct members and multiply with model's rotate matrix and then render.

    This can be accompished with a matrix stack but I haven't implemented it yet.
    Last edited by VirtualAce; 10-10-2004 at 03:27 AM.

  3. #18
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    Suspicious at best. I suppose you could scale your model vertices every frame to get the desired size or you could create the model with the desired size. Either way you still cannot render the final model w/o doing something to it. I do not store the model's as unit vectors so that I do not have to scale them every time I want to use them. My coordinate system is rotated by matrices in the camera class and quite frankly I have no idea how you would call this a speed boost since this is what has to be done to get the desired results.
    What is a vertex? It is the X, Y, Z coordinates of the point.

    We have a point P, whose coordinates are this:

    P-> = [X]i + [y]j + [z]k

    In this case:

    i = (1,0,0)
    j = (0,1,0)
    k = (0,0,1)

    x, y and z are scalars representing the magnitude of i, j and k of the vertex. Intead of doing all of the math to render the billboards (as you posted on the last page) you can just rotate the i, j and k vectors once, and then share them for all of the billboards.

  4. #19
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I am but you if you want to rotate the billboards as they face the camera you must perform another concatenation. Otherwise your rotation will be applied to all billboards. Just because I want my super cool explosion effect to spin and roll, does not mean I want my star to rotate and spin with it.

  5. #20
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    it's the same as only taking into account pitch and yaw but not roll.

  6. #21
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I see no difference in creating a rotation matrix for yaw and pitch but not roll as opposed to creating one for all 3. Either way the same number of multiplies are incurred.

  7. #22
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    Well then it at least serves for another way of doing things.
    I should admit the speed issue is questionable, but what I am sure of is that my method is easier to comprehend at an intuitive level.

    Also, because of the concept I showed for accomplishing this task (which I know works), it might actually help to show how matrix mathematics works...a matrix is sort of an operator that 'operates' on another matrix (a vector is a special case of a matrix). I understand these topics:
    The math involved is very clever and you will probably have to tweak it to find out why it works. The concept is this:

    1. Transpose the view matrix
    2. Take the upper left 3x3 block from the transposed matrix and use that as a rotation matrix.
    3. Combine this matrix with your rotation, translation (position), and scaling matrices.
    4. The quad will always face the camera.
    but I think my way is essentially easier and works just as well (although ultimately matrices have so many interesting properties and my way is just a specific way of accomplishing this task)
    Last edited by Darkness; 10-11-2004 at 02:19 PM.

  8. #23
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    I should admit the speed issue is questionable, but what I am sure of is that my method is easier to comprehend at an intuitive level.
    So you want me to use your method because it's easier - intuitively. Ummm.....lemme think.................NOT!!!!!!!!!!!!!!!!!!!

    And I would not attempt a 3D engine if I did not understand matrix math and matrix concatenation. I've programmed all of this before in pure software under DJGPP including rasterization but thankfully now I don't have to.

    I thought you were actually catching a flaw in my billboard system and instead I find you are only trying to be right not helpful.

    I'm willing to listen to anyone on the board about suggestions they may have. But, in the future, if you do not have a faster algorithm or if you are only posting just to waste my time and bs with me about theory, please refrain from posting.

    Please don't talk to me as though I do not understand 3D mathematics or how my own core engine works. I'm not trying to be mean but we posted about 10 posts that eventually came down to the fact that you did NOT have a faster method.

    Let me put it this way. I don't care who invented the algo, where it comes from, or if it is original. All I care about is SPEED, pure SPEED. If your algo is not faster, I have no reason to change mine.

    Code:
    but I think my way is essentially easier and works just as well (although ultimately matrices have so many interesting properties and my way is just a specific way of accomplishing this task)
    And what are you trying to say. I am using matrices to accomplish this. I'm altering several matrices to fit what I need. I'm really lost as to what you are even saying.

  9. #24
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Ok, got my starfield working. Now it looks as though you are flying through space.

    It was actually pretty easy.

    1. Create local starfield centered around 0,0,0.
    2. Move stars by negative look vector. -> soon to be movement vector
    3. Translate entire field to player position.
    4. Test to see if stars are too far away from 0,0,0. If so regen.
    5. Wash, rinse, repeat.

  10. #25
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    Quote Originally Posted by Bubba
    So you want me to use your method because it's easier - intuitively. Ummm.....lemme think.................NOT!!!!!!!!!!!!!!!!!!!

    And I would not attempt a 3D engine if I did not understand matrix math and matrix concatenation. I've programmed all of this before in pure software under DJGPP including rasterization but thankfully now I don't have to.

    I thought you were actually catching a flaw in my billboard system and instead I find you are only trying to be right not helpful.

    I'm willing to listen to anyone on the board about suggestions they may have. But, in the future, if you do not have a faster algorithm or if you are only posting just to waste my time and bs with me about theory, please refrain from posting.

    Please don't talk to me as though I do not understand 3D mathematics or how my own core engine works. I'm not trying to be mean but we posted about 10 posts that eventually came down to the fact that you did NOT have a faster method.

    Let me put it this way. I don't care who invented the algo, where it comes from, or if it is original. All I care about is SPEED, pure SPEED. If your algo is not faster, I have no reason to change mine.

    Code:
    but I think my way is essentially easier and works just as well (although ultimately matrices have so many interesting properties and my way is just a specific way of accomplishing this task)
    And what are you trying to say. I am using matrices to accomplish this. I'm altering several matrices to fit what I need. I'm really lost as to what you are even saying.
    No need to be harsh, and if you do count the number of operations mine does have fewer.
    See you in 13

  11. #26
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    No need to be harsh, and if you do count the number of operations mine does have fewer.
    I should admit the speed issue is questionable, but what I am sure of is that my method is easier to comprehend at an intuitive level.
    Which is it? Is it faster, or do you just think its faster?

    I'm not being harsh, I'm being realistic. There are several threads you have responded to that are simply inaccurate as far as 3D math is concerned. Ray to triangle and all of those intersections are not as intensive as you claim nor are some of the other and so right now I'm sort of suspicious.
    Last edited by VirtualAce; 10-12-2004 at 07:53 PM.

  12. #27
    Registered User
    Join Date
    Mar 2003
    Posts
    580
    Check it out, I am 100% accurate with everything I have said, I think you just don't know the algorithm I am speaking of.

    You count the speed of an operation by the additions and multiplications it induces, and mine induces less than yours if you go through and count them.

    EDIT:
    ah hah! I realize the confusion:

    I should admit the speed issue is questionable, but what I am sure of is that my method is easier to comprehend at an intuitive level.
    I most certainly did not mean questionable, I honestly meant (and was thinking) trivial!!!!!

    trivial != questionable
    Last edited by Darkness; 10-12-2004 at 08:05 PM.
    See you in 13

  13. #28
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    You did not explain your method thoroughly enough for me to even use it, and besides I'm already storing the vectors in the camera class. The billboard system simply retrieves the matrix and uses it for all billboards in the system - given that they even need to be displayed.

    Anyways updated screenie with some very early starfield shots. Probably will alter this to look better later, but altering the graphics is easy. The system works fine.

    The fuzziness around the stars is a sad result of having to convert the picture to jpg format.

    Also the backdrop is no longer active. I'm working on making it a skybox instead of a sphere.
    Last edited by VirtualAce; 10-12-2004 at 10:55 PM.

  14. #29
    i dont know Vicious's Avatar
    Join Date
    May 2002
    Posts
    1,200
    Honestly i think if you are putting in more planets that it will look perfect without a skybox.

    IMO the pure black just represents the great void of space. Maybe im not just visualizing it well enough but i think that last ss is the best.

    Wonderful work.

    Also, would it be difficult to decrease the size of the atmosphere. I would like to see what it looks like with the atmosphere slightly smaller.

    Note: I am not trying to "correct" you, im just curious.
    Last edited by Vicious; 10-12-2004 at 11:20 PM.
    What is C++?

  15. #30
    S Sang-drax's Avatar
    Join Date
    May 2002
    Location
    Göteborg, Sweden
    Posts
    2,072
    Quote Originally Posted by Vicious
    Also, would it be difficult to decrease the size of the atmosphere. I would like to see what it looks like with the atmosphere slightly smaller.
    Yep, I agree the atmosphere should be smaller.
    Last edited by Sang-drax : Tomorrow at 02:21 AM. Reason: Time travelling

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Polymorphism; Update functions and accessibility
    By CaptainMaxxPow in forum C# Programming
    Replies: 2
    Last Post: 04-23-2009, 08:48 AM
  2. SQLite not performing update
    By OnionKnight in forum C Programming
    Replies: 0
    Last Post: 01-21-2009, 04:21 PM
  3. July 9 2008 MS XP Update
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 12
    Last Post: 07-18-2008, 05:14 AM
  4. ListView Refresh, Update
    By de4th in forum C++ Programming
    Replies: 1
    Last Post: 12-23-2006, 09:13 AM
  5. file index update error
    By daluu in forum C Programming
    Replies: 1
    Last Post: 04-28-2003, 02:47 AM