PDA

View Full Version : Simple Direct3D Perspective/Camera Question




Neutral Gamer
Feb 19, 2008, 10:16 PM
I know this is supposed to be a Mac programming forum but I prefer the people on the Mac Rumors forums so I thought I'd try here first! :D

I have, what I assume is a very simple problem, for which I hope, there is a very simple, staring me in the face solution. Basically I'm drawing a grid of cubes with each cube the same size and at the same z position. The problem is that each cube looks different depending on where in the 3D world it's positioned, e.g. as it gets further to the left you can see more of its right side face than you can when it's in the middle. That's understandable because that's how the REAL world works thanks to the position of the camera and no doubt perspective.

The thing is I want each cube to look the same, i.e. as though it were positioned at (0,0,0). I'm not moving the camera; it's positioned at (0,0,-4) and looking at (0,0,0) and I'm using a perspective projection. I could just use a picture of a cube as a texture and then draw it onto multiple quads but I want to be able to ROTATE certain cubes at random and so need them to remain 3D objects.

At the moment I'm using multiple viewports; rendering each cube to a separate viewport. But changing the viewport 50 times each render pass doesn't *seem* like a very efficient idea. I assume there's a much simpler and elegant solution out there - can someone tell me what it is? No doubt something to do with adjusting the View or Projection matrices each time to take into account the position of the cube?

Any help would be much appreciated!
Cheers :)



garethlewis2
Feb 20, 2008, 02:29 AM
I don't know if this is possible with D3D but you can try and tell the camera to parallel projection instead of perspective projection. If that is not going to work, then you can set the focal length of the camera matrix to some monstrous value and that will simulate parallel projection.

garethlewis2
Feb 20, 2008, 02:29 AM
Sorry, it might be called orthogonal projection in D3D.

lazydog
Feb 20, 2008, 03:38 AM
An orthogonal projection sounds good.

You could also try this:- Instead of putting all your cubes at the same z distance, ie all in a line, place them on the circumference of a circle with the camera at the centre of the circle. Also, orientate all the cubes so that they are facing the camera. Since they are all at the distance from the camera, they should all look the same size.


b e n

Neutral Gamer
Feb 20, 2008, 04:07 PM
Thanks for the replies garethlewis2 and lazydog. I too originally thought that an orthogonal projection would be the answer to my problems but weird stuff seems to happen when I try and rotate objects using it. I can't remember exactly what but I'll try it again and change the focal length as well and document the results.

lazydog, the idea about the circle and the camera being in the centre is a GENIUS idea! I don't know how you managed to come up with that; it makes logical sense and I can't wait to try it out.

Been out all day and am tired and need to sleep but I will try both solutions out tomorrow and let you know how it goes.

Cheers again to both of you for the help so far, it's good to see there's some Mac Rumors members who understand 3D programming cos I definitely find it complicated at times! I primarily program using Win32 and C++ and love pointers and low level programming but I just seem to find it hard to *imagine* the results of 3D operations. :)