Y real 90 degree

ey

I made a camera with OpenGL

The camera works with adding XYZ directory

I need [-90,90] degrees from Y rotate but it use [-45,45] degrees...
I know why but I don't know how to solve

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#define math_pi atan(1)*4

#define math_deg(x)({__typeof__(x)_x=(x);_x/(math_pi/180);})
#define math_rad(x)({__typeof__(x)_x=(x);_x*(math_pi/180);})

GLdouble  cam_pos        [3]  ={-50,20,0};
GLdouble  cam_dir        [3]  ={1,0,0};
GLdouble  cam_xlookangle      =90;
GLdouble  cam_ylookangle      =0;

//cameraf

void cam_update(){
    cam_dir[0]=sin(math_rad(cam_xlookangle));
    cam_dir[1]=sin(math_rad(cam_ylookangle));//this going to use [-45,45] degrees but I want [-90,90]
    cam_dir[2]=cos(math_rad(cam_xlookangle));
};

void cam_display(){
    gluLookAt(cam_pos[0]           ,cam_pos[1]           ,cam_pos[2],
              cam_pos[0]+cam_dir[0],cam_pos[1]+cam_dir[1],cam_pos[2]+cam_dir[2],
              0.0                  ,1.0                  ,0.0);
};

/*GLUT

void event_motion(int x,int y){
    if(mos_directchanged){mos_directchanged=GL_FALSE;return;};

    if(mos_btns[GLUT_RIGHT_BUTTON]){
        cam_xlookangle-=(double)(x-mos_x)/5.0;
        cam_ylookangle-=(double)(y-mos_y)/5.0;
        cam_ylookangle=cam_ylookangle>90.0?90.0:(cam_ylookangle<-90.0?-90.0:cam_ylookangle);

        cam_update();

        mos_directchanged=GL_TRUE;

        glutWarpPointer(mos_x,mos_y);
        return;
    };

    mos_x=x;
    mos_y=y;

    //glutPostRedisplay();
};
*/
Last edited on
I forgot to change the title fuck...
@Tomhet

Have you tried using GLdouble cam_ylookangle = -90; instead?
http://www.opengl.org/sdk/docs/man2/xhtml/gluLookAt.xml

I don't see "degrees" or trigonometry in that.
@whitenite1
eh won't solve...

@keskiverto
"degrees" meant to be what can see with the camera UP and DOWN...
if I say in radians then I should have said PI/4 ... bullshit

with that shit tutorial you didn't helped me

my camera is good but with if the direction {x,1,x} it can be only 45 degrees (what we can see...)
but agian I want UP and DOWN 90 degrees (what we can see with the camera)
Last edited on
That is not a tutorial. That is the documentation of the function.

Your comment shows that you are looking at wrong function and even after reading its documentation you don't see that.

perspective, projection, view volume -- those keywords you should look for.
@keskiverto

Thanks but I already had those things... (btw I rewrote my code)

My problem was, I didn't knew how to add UP and DOWN 90 degrees in 2D coordinate table (mouse x,y)

pos[3]={0,0,0};

dir_lookingdown90={0,-1,0};
dir_lookingup90 ={0, 1,0};

after I slept a big I got an idea and I solved with an easy move...
and I won't show in the next code but UP and DOWN shouldn't be fully 90 degrees so I just limited to "89.95f"

1
2
3
4
cam_dir[1]=sinf(math_rad(cam_rot[1]));//cam_rot[1] max 89.95f min -89.95f

cam_dir[0]=cosf(math_rad(cam_rot[0]))*(1-math_abs(cam_dir[1]));
cam_dir[2]=sinf(math_rad(cam_rot[0]))*(1-math_abs(cam_dir[1]));


whole code: http://pastebin.com/C5Tji1C8
Last edited on
I think I finally see. Let me rephrase:

You have two positions: Center and Eye. Eye is at fixed distance from Center.
You have direction: Up. You also have direction toCamera, which is like from Center to Eye. (Eye == Center + toCamera)

At start the toCamera and Up are perpendicular.

You want to be able to rotate around axis that is perpendicular to both toCamera and Up, i.e. around normal of a plane defined by those two directions. We could call that direction Axis. Cross-product of normalized toCamera and Up.

You want to limit the rotation, so you have to keep the original toCamera and Up and an Angle. The Center does not change.

So, you do decide an Angle. Then you can calculate rotation R. Now you can compute Eye' = R * toCamera + Center, and Up' = R * Up. Then you can feed Center, Eye', and Up' into gluLookAt().

Alternatively, you use glRotate() with Axis and Angle. Obviously, if Center is not {0,0,0}, some glTranslate is required too.


Is this a semi-accurate description of your problem?
Topic archived. No new replies allowed.