Sign in to follow this  

DirectX Camera

This topic is 2634 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

Is there a way to position the camera in such a way that World location (0,0) is in the bottom left of my window?... Meaning i will only be working in quadrant1, +x/+y locations.

Edit:
My overall issue is understanding how to put the camera in some kind of boundary. So the user cant scroll too far in any direction and see "nothingness".

Edit:
Is this a stupid or vague question? This is the 3rd forum I've tried without so much as a hint of what to do, or any questions about clarifying what I'm asking.

[Edited by - Cazicss on September 26, 2010 4:27:05 AM]

Share this post


Link to post
Share on other sites
I'm not sure about what you want to do, but try to calculate the far frustum corners of your camera. Look at this website: http://www.lighthouse3d.com/opengl/viewfrustum/index.php?defvf

The set camera position to:
X = fbl.x
Y = fbl.y
Z = farDist

Read the tutorial on the link I wrote and you will understand what does fbl mean.

Can you explain what you want to do a little more?

Share this post


Link to post
Share on other sites
First off i have to thank you! .. First person to try to help.

Ok, what i've done is started the camera positioned to be above location (0,0,0) and to lokat (0,0,0) .... but this puts (0,0,0) in the center of my screen. I want (0,0,0) in the bottom left corner so that the left and bottom edges of my screen are in alignment with the y and x axis. Does that make more sense?.. Im not sure how to tell how far to move the camera to the right and up to ensure that im in alignment with the 2 axies

EDIT: I do not want to see negative locations on screen.

Share this post


Link to post
Share on other sites
Maybe what I'm trying to do isn't important. If you play a game such as, say starcraft, you can scroll the screen up,down,left,right ..but when you reach the edges of the map your camera stops so that u can scroll no further.

I was assuming keeping the screen in the +x/+y section of the world would keep the math easier so i didnt want to move allow the camera to move into -x or -y values... since i wouldnt be putting any terrain or objects in that space anyway.

Share this post


Link to post
Share on other sites
Well, forget my first post... it wont work :S

I guess you have to calculate the the far frustum corners with current camera position (0,0,0) and look at (0,0,far plane z);

Then you set the camera position to (far top right frustum corner x, far top right frustum corner y, 0) and look at ( far top right frustum corner x, far top right frustum corner y, far top right frustum corner z);

Look at this image:
description of your image

The black rectangle is the far plane of frustum when camera position is (0,0,0) and look at is (0,0,far plane z), and the red rectangle is when the camera position is (far top right frustum corner x, far top right frustum corner y, 0) and look at ( far top right frustum corner x, far top right frustum corner y, far top right frustum corner z). Im not sure if it will work.

P.S. Read the tutorial is posted a link in my first topic. It will tell you how to get the far frustum top right corner position (ftr).

Share this post


Link to post
Share on other sites
Hmm so it sounds like i need to look into these "far frustrum corner" things. I'll take a longer look at your link and try to do some extra research into the "far frustrum". For now I'm headed to bed and will post back in this thread when I've had a chance to go over some things.

Thanks again =). Most appreciated to have a direction ^_^

Share this post


Link to post
Share on other sites
It's a fairly easy topic to grasp, assuming you have a working knowledge of vectors and trig. I'm going to work in 2D for a sec, but the principle is the same



L R imagine a triangle lying on the XZ plane, running from camera
\ / origin, to 2 points that each lie on opposite edges of the far
\ / plane of your frustum. I'll call them Left,Right,and Camera
C




You can see that angle LCR is the (FOV)Field of view for this axis. Also note that if segment LR (not shown) was cut in half at point F, that a segment CF is perpendicular to LR. Knowing this, we can use trig to solve for C using 1/2 our FOV using a position of (0,far-near) for L.

Now picture the same thing on the YZ plane, using Top,Bottom,Camera for the 3 points of the frustum...

So by constraining the Bottom-Left corner of the far plane to be (0,0,far) you will get a frustum that exists only in the first quadrant, (though we should be using octant, as it is the proper term for 3D, but would depend most likely on Handedness



Share this post


Link to post
Share on other sites
Are you using ortho projection? I.e, do you use D3DXMatrixOrthoLH to create your projection matrix?

If you are, then the minimum position for your camera is x = W/2.0f and y = H/2.0f, where W and H are the width and height values used to create your projection matrix.

Share this post


Link to post
Share on other sites
Quote:
Original post by Buckeye
Are you using ortho projection? I.e, do you use D3DXMatrixOrthoLH to create your projection matrix?

If you are, then the minimum position for your camera is x = W/2.0f and y = H/2.0f, where W and H are the width and height values used to create your projection matrix.


Im using D3DXMatrixPerspectiveFovLH(&m_Projection, D3DX_PI/4, 500/500, 1, 500);

Share this post


Link to post
Share on other sites
Quote:
Original post by Cazicss
Is there a way to position the camera in such a way that World location (0,0) is in the bottom left of my window?... Meaning i will only be working in quadrant1, +x/+y locations.

Edit:
My overall issue is understanding how to put the camera in some kind of boundary. So the user cant scroll too far in any direction and see "nothingness".

Edit:
Is this a stupid or vague question? This is the 3rd forum I've tried without so much as a hint of what to do, or any questions about clarifying what I'm asking.

Your question isn't stupid. It's more a matter of not making much sense, I'm afraid, in terms of a 3D perspective view. Controlling a perspective view in the way you describe, i.e., never "seeing" anything with x or y coordinates < 0, would be a bit difficult.

Consider your perspective viewing frustum, as viewed from above the eyepoint.



From your description, it sounds like there's a "negative" region you want to prevent the user from seeing. If so, the camera would have to face in a direction such that one of the world axes would always have to the left of the user's eyepoint to hide that negative region. That is, your camera positioning calcs would have to examine the current position, the aspect ratio of the screen, etc., etc.

It's possible, I suppose, but more complicated than I personally would want to get into.

Share this post


Link to post
Share on other sites
Hmmm..
Well I think I see your point. Though different styles of games will have harder time accomplishing the boundaries. If this were a First Person Shooter ... not showing negatives could be irrelevant since walls are erected to keep the player within certain bounds, and with him/her the camera.

But for me, its a top-down "bird eye" view. In the game I referenced before, "Starcraft", the camera cannot be rotated left/right or zoomed. The mini-map of the game shows the whole "world" and a rectangle depicting the camera's viewing rectangle within that world.

I think you have given me enough to figure something useful out. This forum is very helpful. Thanks again =)

Share this post


Link to post
Share on other sites

This topic is 2634 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this