Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I have screen with dimensions: 800x600. The object that I want to rotate around is located at (400,300, -50) - center of the screen. Orthogonal projection: Near plan - 0.1f, far plane - 1000.0f left - 0, bottom - 0, right - 800, top - 600

Camera: position at (0,0,0) look at (0,0,-50) up vector (0,1,0)

Now what I'm doing to rotate is calculate the X of "look at" using: 0 + width * cos(A). Y remains the same (0). Z is calculated using: -50 + width * sin(A).

Now the problem that I'm facing is that after some angle the object starts to disappear, and it doesn't rotate around the object. What can be the problem?

share|improve this question
1  
According to your math, your camera will orbit around 0,0,-50 with a radius of width. But you are saying the object you wish to orbit is at 400,300,-50. Correct? –  UnderscoreZero May 17 '13 at 22:06
    
yes, so in order to fix it, I need to change the look at values? Let's try it –  Oleg Bondarenko May 18 '13 at 8:23

1 Answer 1

The image of a point A under a rotation around another point B (an affine rotation if B is not the origin of the space) is A', with

A' = B + R*(A-B)

where R is the matrix of the associated linear rotation.

For example, in dimension 2, say you want to rotate A = (1,0) around B = (1,1) by 90 degrees counter-clockwise. That will yield (2,1). Make a picture if needed. And, if we call R the matrix of the linear counter-clockwise rotation of angle 90 degrees, we have

R = (0 -1)
    (1  0)

and

(1,1) + R*( (1,0) - (1,1) ) = (1,1) + R*(0,-1)
                            = (1,1) + (1,0)
                            = (2,1)

Now, the solution to your problem actually depends on your implementation of world and camera geometry. You can either rotate your camera around point B or you can "rotate the world" around the camera by the inverse of the previous rotation (as usual in the "ProjectionMatrix * CameraMatrix * ModelMatrix * positionOfVertex" part of a vertex shader, if it's OpenGL or DirectX you're using).

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.