Jump to content
  • Advertisement
Sign in to follow this  
freakybarber

[XNA 3D] Camera Problems

This topic is 2702 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hello everyone,

I've been busy making the transition from 2D to 3D XNA Game development and I'm having some problems implenting a moving/rotating camera. The current problem is that I'm kind of confused what approach to use when implementing an FPS style camera (I'll later be switching to a more top down approach, but since I've been busy loading models in XNA - with succes I might add, I'm really excited - I wanted a way to fly around the gameworld to check if all models are being rendered correctly).

I've been trying to translate and rotate the camera by manipulating the view matrix, but now I'm wondering if the corrent approach would be a static camera at the origin and translating and rotating the world around upon drawing time in correspondence to user input (player movement/looking around), instead of fiddeling with the view matrix.

Which would be the correct appoach? Translating and rotating the view matrix (actually "moving" the camera through the game world) or translating and rotating the world matrix (to create the "illusion" of movement).

I have a book on 3D math lying right next to me, I was just wondering which would be better for an FPS style camera (and if the desired effect if even obtainable using the view matrix).

If I'm missing out of anything blatantly obvious please fill me in. I'm here to learn.

Share this post


Link to post
Share on other sites
Advertisement
Isn't the end result really the same thing - geometry being translated into position to be rendered? I remember having a similar question when I was first getting into 3D stuff, and it really didn't make any difference. Either way you are really doing the same thing - transforming a bunch of geometry based on how it's viewed.

The XNA samples on the App Hub might be of some use, if you haven't taken a look at them already. Like this one:

http://create.msdn.com/en-US/education/catalog/sample/chasecamera

Share this post


Link to post
Share on other sites
Translating the world matrix is the wrong approach. Thats why the view-matrix is there, so you dont have to create the illusion of a camera. The world matrix is for translation, rotation and scalation of the objects ad nothing more, the view-matrix defines the camera. You can do it on other ways, like i did my first 2d sidescroller with just moving every sprite instead of having a real camera. Its just awkward.

Share this post


Link to post
Share on other sites

Hello everyone,

I've been busy making the transition from 2D to 3D XNA Game development and I'm having some problems implenting a moving/rotating camera. The current problem is that I'm kind of confused what approach to use when implementing an FPS style camera (I'll later be switching to a more top down approach, but since I've been busy loading models in XNA - with succes I might add, I'm really excited - I wanted a way to fly around the gameworld to check if all models are being rendered correctly).

I've been trying to translate and rotate the camera by manipulating the view matrix, but now I'm wondering if the corrent approach would be a static camera at the origin and translating and rotating the world around upon drawing time in correspondence to user input (player movement/looking around), instead of fiddeling with the view matrix.

Which would be the correct appoach? Translating and rotating the view matrix (actually "moving" the camera through the game world) or translating and rotating the world matrix (to create the "illusion" of movement).

I have a book on 3D math lying right next to me, I was just wondering which would be better for an FPS style camera (and if the desired effect if even obtainable using the view matrix).

If I'm missing out of anything blatantly obvious please fill me in. I'm here to learn.



@Moe, unfortunately the end result is not the same thing.

@freaky, let's look at it another way. Would you want to waste processor time changing the world matrices of every object in the scene just because one of them has moved? I think not. The camera is a single object, and moving IT should result in a change of IT's world matrix ONLY. The view matrix is simply the inversion of that(changes from world to camera rather than camera to world)

Share this post


Link to post
Share on other sites

@freaky, let's look at it another way. Would you want to waste processor time changing the world matrices of every object in the scene just because one of them has moved? I think not. The camera is a single object, and moving IT should result in a change of IT's world matrix ONLY. The view matrix is simply the inversion of that(changes from world to camera rather than camera to world)


This was exactly what I was thinking about. When dealing with a simple scene like mine (3 models of around 100 polygons total) I might not see a performance hit when using the world matrix approach, but when I start to draw a large amount of objects the afore mentions performance hit might show itself. Thanks for advice everyone. I found the error in my view matrix rotation calculation that I wasn't able to find last night (it was like 3 am after all, I was just staring blindly at it the time I guess) and I have rotation on the Y axis now. Today I plan to also add rotation on the X axis.

Share this post


Link to post
Share on other sites
I have a complete snippet for an orbital camera at my brand new website, www.madmenyo.net . You could easily modify it to an FPS camera, swapping the cameraposition with the player location and use the cameraposition as the target where the camera is looking. Anyway, i tried to keep it as simple as possible and commenting out almost each line so you could learn pretty much from it.

Anyway, i'm pretty much a newbie on gameprogramming too but xna is easy enough for me to pick up quickly.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!