1. ## 3d/2d camera setup

I'm trying to make my 2d puzzel 3d.

At the moment I'm using this camera setup:

glMatrixMode(GL_PROJECTION)
gluPerspective(60., 1920 / float(1080), 900., 1000.)
glMatrixMode(GL_MODELVIEW)
gluLookAt(960,540, math.sqrt(3)*540, 960,540,0,0,1,0)

It works but I get a view as if I'm looking down on the middle of the puzzle. (When a piece is in the lower left corner I see the top and right sides of it and when it's in the top left I see the lower and left side of it)

pic: http://pix.sonhult.se/puzzle.jpg

What I want is to have the camera as if I was standing infront (below) the screen.

I've drawn a picture of it:

http://pix.sonhult.se/camera2.jpg

And it's important that the x, y plane in z = 0 is linear since that's where I detect hits and stuff...

It should be fairly easy to setup I think but I can't seem to do it

2. ## Re: 3d/2d camera setup

What I want is to have the camera as if I was standing infront (below) the screen.
When a piece is in the lower left corner I see the top and right sides of it and when it's in the top left I see the lower and left side of it)
From the above statements, it seems you need to set you Z coordinate.

note that positive z direction is towards the viwer ( in front ) of screen while it is negative past screen. Hope this helps.

3. ## Re: 3d/2d camera setup

Originally Posted by awhig
From the above statements, it seems you need to set you Z coordinate.
? Ofcourse I'm setting z-coordinates if I'm trying to draw something in 3d

Originally Posted by awhig
note that positive z direction is towards the viwer ( in front ) of screen while it is negative past screen. Hope this helps.
Oh, make that 960ish, -500ish, 1500ish for desired camera position..

The thing is that I can set this up fine myself IF i just render it in a small box in the top of my screen, then I get the perspective I want in that box, but I can't seem to zoom in on that box.

glMatrixMode(GL_PROJECTION)
gluPerspective(60., 1920 / float(1080), 900., 3000.)
glMatrixMode(GL_MODELVIEW)
gluLookAt(960,-500, math.sqrt(3)*(1080+500), 960,-500,0,0,1,0)

pic: http://pix.sonhult.se/puzzle2.jpg

4. ## Re: 3d/2d camera setup

change
gluPerspective(60., 1920 / float(1080), 900., 3000.)

900,3000 -> say 10,10000 (thus less danger of clipping)

though I think u prolly dont want perspective, just a 3d effect, thus change over to glOrtho( ... ) or change fov to something low eg 20 (which is still perspective but not as major)

XXX = 960,-500,-1500 (in relation to 0,0->1920,1080)
though be aware 960/1920 == 0.5 but u prolly want 0.0

vec3 N = return_vectors_normal( XXX ); // or whever u want
vec3 C = center of the scene
float D = camera_distance;
gluLookAt( C.x + N.x*D, C.y + N.y*D, C.z + N.z*D, C.x,C.y,C.z, .... )

WRT vectors normal
http://en.wikipedia.org/wiki/Unit_vector
// sorry wiki is the worse source for math explanations
try this
http://www.fundza.com/vectors/normalize/index.html

gahhh... my explaining perhaps I have the necessary skills to write for wiki

5. ## Re: 3d/2d camera setup

Here is yet another picture of what I want to achive:

http://pix.sonhult.se/puzzle3.jpg

I want this perspective but I want that plane that is tilted in this view to be mapped to the pixels (0, 0) (1920, 1080)

(The big green box is a quad with the vertexes (0, 0, 0) (1920, 0, 0) (1920, 1080, 0) (0, 1080, 0), and I want that quad to cover the entier view of the camera, no more no less and I don't want it to change dimensions in anyway..

this is drawn with

gluPerspective(60., 1920 / float(1080), 900., 3000.)
glMatrixMode(GL_MODELVIEW)
gluLookAt(960,-500, 1000, 960,540,0,0,1,0)

(The gluLookAt isn't exactly what you recomended but it's in the same ballpark so calculating an exact position with the forumla you gave me would yeild a simular result (To me it seems like I choosed a distance of 1000ish and a normal of (0, -1/sqrt(2), 1/sqrt(2)) )

(Oh and I know you recomended some changes to gluPerspective that I ignored )

So basicly what I want to do is render everyting from one point of view and then just scale/translate it to cover the entire screen. (I think if I could somehow grab the corners of the green quad and drag them to the corners of the screen I would get exactly what I want...)

edit: math

6. ## Re: 3d/2d camera setup

glFrustum(0, 1920., 0, 1080., 1000, 10000)
glMatrixMode(GL_MODELVIEW)

gluLookAt(0,0, 1000, 0,0,0,0,1,0)

Did the trick for me (or almost anyway, but I think I can fix the last part)

Thanks for the help

edit: "final" code and look:

Code :
```x_offset = 960
y_offset = -500
glMatrixMode(GL_PROJECTION)
glFrustum(0-x_offset, 1920-x_offset, 0-y_offset, 1080-y_offset, 1000, 10000)
glMatrixMode(GL_MODELVIEW)
gluLookAt(x_offset,y_offset, 1000, x_offset,y_offset,0,0,1,0)```

http://pix.sonhult.se/puzzle4

It's not nearly done (still pleanty of work with light/size/bumpmapping and so on), but now atleast the camera is where I want it (and I know how to move it )

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•