Advertisement

Stars and such

Started by May 31, 2002 03:31 PM
3 comments, last by myme15 22 years, 6 months ago
I''m probably gonna sound like an idiot, but here''s my problem anyway: I want to make a scrolling starfield (with stars at different depths) where stars that reach the bottom of the screen loop back to the top to make it seem like it is scrolling forever. My problem: is there a way to implement this in Direct3D 8 without constantly locking and unlocking a vertex buffer filled with the coordinates of the stars? Things are not what they are.
Well, you could use matrices (assuming you're using untransformed coordinates). Just have a single star that you draw many times at different positions (or a set of stars, each at different depths).

But personally, I'd just go with the lock - you'll only need to lock the buffer once per frame, which shouldn't kill performance (much), and you'll then be able to draw all the stars with one Draw[Indexed]Primitive call, which is good (in theory, if you call Draw[Indexed]Primitive with anything less than 200 vertices/indices, then it will take just as long as if you had drawn 200 verts)

EDIT:: This may have been better in the DirectX forum.

Hope that helps,

John B

[edited by - JohnBSmall on May 31, 2002 4:50:54 PM]
The best thing about the internet is the way people with no experience or qualifications can pretend to be completely superior to other people who have no experience or qualifications.
Advertisement
Imagine a tape twice as wide as your screen, and the screen moving along that window, jumping back to the beginning when it reaches the end. (screen pos = fractional part of ( Xgame / screen width ))

------------------------* |  *     * | *    *  |*    *    |-> *     *  |  *    *  |*     *------------------------  


The stars will appear to move from right to left. To avoid a discontinuity when you go back to the beginning, make it so the 'left screenful' of the tape is the same as the 'right screenful'.

To do so, just render your stars twice, one being translated by the width of the screen. Now, you move the screen along this track by doing an appropriate translation (-Xpos of the screen) before starting to render the stars.

Hope it was clear. Your star coordinates never change, you just move the 'view window'

Edit: clarified the 'render twice'

Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]


[edited by - Fruny on May 31, 2002 5:43:30 PM]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan
Thanks a lot for the replies.

Fruny: That's a great idea. Thanks.

Things are not what they are.


[edited by - myme15 on May 31, 2002 5:40:48 PM]
That''s exactly what I suggested you got it perfectly, I just didn''t express myself clearly


Documents [ GDNet | MSDN | STL | OpenGL | Formats | RTFM | Asking Smart Questions ]
C++ Stuff [ MinGW | Loki | SDL | Boost. | STLport | FLTK | ACCU Recommended Books ]
"Debugging is twice as hard as writing the code in the first place. Therefore, if you write the code as cleverly as possible, you are, by definition, not smart enough to debug it." — Brian W. Kernighan

This topic is closed to new replies.

Advertisement