Moving Camera or Moving objects?

Started by
2 comments, last by Misantes 9 years, 8 months ago


I want to program a "star wars" starfield with objects moving towards the screen.

What would be the OpenGL principle behind this? How does it work in principle with OpenGL?

- Do I have stationary objects and move the camera?
- Do I have a stationary camera and move the objects towards the camera?

Thanks for help.

Advertisement
Which way makes sense?

Do you want to have a stationary camera with things flying past or do you want the camera to fly through a field of stationary objects?
If you are talking about Star Trek and the little star-like dots that fly past, it’s the camera moving through a field of stationary objects (if you reference Star Wars it could be anything flying by the camera).


This has nothing to do with OpenGL. Whatever graphics API you are using, do whatever makes sense.


L. Spiro

I restore Nintendo 64 video-game OST’s into HD! https://www.youtube.com/channel/UCCtX_wedtZ5BoyQBXEhnVZw/playlists?view=1&sort=lad&flow=grid

The farther that you go from the origin, the greater the float imprecision.

Moving the view point is the most natural choice, but you will have to change the way that you compute positions to lessen the effect.
- http://stackoverflow.com/questions/1930421/seamless-transitions-of-scale-over-large-distances-3d-rendering
- http://stackoverflow.com/questions/5010612/increase-precision-in-directx-with-high-range-positions
- http://www.gamedev.net/topic/208532-big-coordinate-values-in-direct3d/

As a beginner myself, I was also little confused on this. So, I thought I'd pipe in with a sort of simple explanation here. But, it really comes down to a semantic problem. You have two basic ways of moving things. You can translate the ModelMatrix, which moves the object's position in "worldspace," or you can change the ViewMatrix. translating the ViewMatrix is kind of equivalent to moving the entire world (you're essentially moving the "world center." Whether you want to think of it as moving the "camera" or moving the entire world is kind of a moot point(in my opinion, feel free to correct me on this).

For my own little space simulator, I essentially alter the ViewMatrix to "fly" my character's ship through the world, and translate the ModelMatrix of the stars/planets and such for their own orbits around their stars, etc(it's a little more complicated, but that's the general gist of the movement).

I highly recommend:

http://www.opengl-tutorial.org/beginners-tutorials/tutorial-3-matrices/

as it offers a pretty good explanation of matrix translations. If you're like me, you'll need to read it more than once tongue.png

But, it all boils down to your relationship between your Model and your View matrices (and also the projection matrix, but that's only tangentially related to your question).

For the "star trek" effect, I personally use a particle system to just make tons of little particle debris that flies toward the camera (while altering the VIewMatrix to fly) as my ship doesn't fly nearly fast enough through the planets and such to really give that effect. If you're really travelling that fast in the game you might want to consider something along those lines as depending on how large your object class is, as you may find yourself running into problems generating that many entities (unless you have a clever workaround, I'm sure there is one). A particle system is way beyond the scope of this explanation though. But, again, If you're travelling that fast, you may need to look at alternative methods rather than just creating objects and moving by them.

And my sincerest apologies if this isn't quite what you were asking. I don't mean to be condescending at all. I just got the impression you may have been looking for a more basic explanation of things. If you totally understand all this already, feel free to disregard my comment smile.png

If you're truly just looking for the effect, doing this through a glsl shader might be your best bet.

I didn't search that hard, but something along the lines of:

https://glsl.heroku.com/e#18570.0

https://glsl.heroku.com/e#18559.0

or

https://glsl.heroku.com/e#18500.0

Beginner here <- please take any opinions with grain of salt

This topic is closed to new replies.

Advertisement