The MASM Forum Archive 2004 to 2012

Project Support Forums => OpenGL Forum => Topic started by: Farabi on August 28, 2005, 01:35:12 AM

Title: gluLookAt
Post by: Farabi on August 28, 2005, 01:35:12 AM
How to use gluLookAt? Here is my last rotation code.


invoke glPushMatrix
invoke glTranslatef, CFLT(0.0), CFLT(0.0), CFLT(-5.0)


invoke glTranslatef, pos3_x, pos3_y, pos3_z
invoke glRotatef, RotX, CFLT(1.0), CFLT(0.0), CFLT(0.0)
invoke glRotatef, RotY, CFLT(0.0), CFLT(1.0), CFLT(0.0)
invoke glRotatef, RotZ, CFLT(0.0), CFLT(0.0), CFLT(1.0)


Should I remove this all code and replace is with a single code gluLookAt?
Title: Re: gluLookAt
Post by: hitchhikr on August 28, 2005, 01:53:48 AM
No.

gluLookAt is used to define a viewpoint, like a camera. You can use it to move inside a scene, tho.
Title: Re: gluLookAt
Post by: Farabi on August 28, 2005, 04:11:55 AM
Hai. I invoke gluLookAt but MASM32 show an error. It says it is too complex.
Title: Re: gluLookAt
Post by: hitchhikr on August 28, 2005, 05:21:30 AM
Paste the code.
Title: Re: gluLookAt
Post by: Farabi on August 28, 2005, 05:39:00 AM

; invoke gluLookAt,dword ptr[x_eye],dword ptr[x_eye+4],dword ptr[y_eye],dword ptr[y_eye+4],dword ptr[z_eye],dword ptr[z_eye+4],dword ptr[x_cntr],dword ptr[x_cntr+4],dword ptr[y_cntr],dword ptr[y_cntr+4],dword ptr[z_cntr],dword ptr[z_cntr+4],dword ptr[x_up],dword ptr[x_up+4],dword ptr[y_up],dword ptr[y_up+4],dword ptr[z_up],dword ptr[z_up+4]



I try to replace it with this


Push dword ptr[z_up+4]
Push dword ptr[z_up]
Push dword ptr[y_up+4]
Push dword ptr[y_up]
Push dword ptr[x_up+4]
Push dword ptr[x_up]
Push dword ptr[z_cntr+4]
Push dword ptr[z_cntr]
Push dword ptr[y_cntr+4]
Push dword ptr[y_cntr]
Push dword ptr[x_cntr+4]
Push dword ptr[x_cntr]
Push dword ptr[z_eye+4]
Push dword ptr[z_eye]
Push dword ptr[y_eye+4]
Push dword ptr[y_eye]
Push dword ptr[x_eye+4]
Push dword ptr[x_eye]
call gluLookAt


But the object is not appear. THis is the data I input.


x_eye dq 0.0
y_eye dq 0.0
z_eye dq -5.0

x_cntr dq 0.0
y_cntr dq 0.0
z_cntr dq 0.0

x_up dq 30.0
y_up dq 30.0
z_up dq 30.0
Title: Re: gluLookAt
Post by: hitchhikr on August 28, 2005, 06:18:58 AM
Normally it should work provided that you don't modify the matrix afterwards.

Be sure that you save/restore the modelview matrix before/after using it (glPushMatrix/glPopMatrix) or that you reset it before (glLoadIdentity).
Title: Re: gluLookAt
Post by: ninjarider on September 02, 2005, 12:32:11 PM
farabi,
  im not sure if ur code for gllookat works yet or not but i noticed something in ur variables.
i notice u have all of your x_up, y_up, z_up set to 30, which means the camera wouldn't be moving in the direction u want it to move. try using x_up = 0, and z_up = 0 and y_up = 1.
Title: Re: gluLookAt
Post by: Farabi on September 15, 2005, 06:58:02 AM
Quote from: ninjarider on September 02, 2005, 12:32:11 PM
farabi,
  im not sure if ur code for gllookat works yet or not but i noticed something in ur variables.
i notice u have all of your x_up, y_up, z_up set to 30, which means the camera wouldn't be moving in the direction u want it to move. try using x_up = 0, and z_up = 0 and y_up = 1.

Hai. Yes it is working with your variable. Creating the camera is confusing and frank camera code is not easy to implement.
I found this on my research.


void orientMe(float ang) {

lx = sin(ang);
lz = -cos(ang);
glLoadIdentity();
gluLookAt(x, y, z,
      x + lx,y + ly,z + lz,
  0.0f,1.0f,0.0f);
}

void moveMeFlat(int direction) {
x = x + direction*(lx)*0.1;
z = z + direction*(lz)*0.1;
glLoadIdentity();
gluLookAt(x, y, z,
      x + lx,y + ly,z + lz,
  0.0f,1.0f,0.0f);
}



That is code for C++. It seems will work but translate it to MASM is not easy thing. Maybe you have any clue?
Title: Re: gluLookAt
Post by: ninjarider on September 15, 2005, 02:35:44 PM
well i couldn't help u with the fpu functions. still havn't learned them. but maybe a better understanding of the gllookat function might help.
gllootat (x1, y1, z1, x2, y2, z2, x3, y3, z3)

x1 is the x loacation of the camera
y1 is the y
z1 is the z

x2 is the x coordinat the camera is looking at.
y2 is the y coord
z2 is the z coord

what u specify in the x2, y2, and z2 is what should be in the exact center or your window,

kinda hard to explain the x3, y3, z3. best i can think of is the camera tilt
if u were to have:
{x3, y3, z3} = {0,1,0} then the camera would be upright. any camera movement would move up
{x3, y3, z3} = {1,0,0} then the camera would be on its side. and camera movement would be to the right
{x3, y3, z3} = {0,-1,0} then the camera would be upside down. any camera movement would move down
{x3, y3, z3} = {-1,0,0} then the camera would be on its side again, but any camera movement would move the the left.

hopefully this will clean up any misunderstanding u have.
Title: Re: gluLookAt
Post by: Farabi on September 17, 2005, 09:15:10 AM
Quote
x3, y3, z3} = {-1,0,0} then the camera would be on its side again, but any camera movement would move the the left.

To left if I add the x1?
Title: Re: gluLookAt
Post by: MichaelW on September 17, 2005, 01:42:46 PM
Farabi,

I don't know anything about the gluLookAt function, but wouldn't it be easier to alter the prototype and just pass QWORDs in the invoke statement, like so:

; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    include \masm32\include\masm32rt.inc

    gluLookAt PROTO \
     :QWORD,:QWORD,:QWORD,:QWORD,:QWORD,:QWORD,:QWORD,:QWORD,:QWORD

    includelib \masm32\lib\glu32.lib
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    .data
      eyex    DQ 0
      eyey    DQ 0
      eyez    DQ 0
      centerx DQ 0
      centery DQ 0
      centerz DQ 0
      upx     DQ 0
      upy     DQ 0
      upz     DQ 0
    .code
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
start:
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
    invoke gluLookAt, eyex,
                      eyey,
                      eyez,
                      centerx,
                      centery,
                      centerz,
                      upx,
                      upy,
                      upz

    mov   eax, input(13,10,"Press enter to exit...")
    exit
; «««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««««
end start


00401000                    start:
00401000 FF3544304000           push    dword ptr [403044h]
00401006 FF3540304000           push    dword ptr [403040h]
0040100C FF353C304000           push    dword ptr [40303Ch]
00401012 FF3538304000           push    dword ptr [403038h]
00401018 FF3534304000           push    dword ptr [403034h]
0040101E FF3530304000           push    dword ptr [403030h]
00401024 FF352C304000           push    dword ptr [40302Ch]
0040102A FF3528304000           push    dword ptr [403028h]
00401030 FF3524304000           push    dword ptr [403024h]
00401036 FF3520304000           push    dword ptr [403020h]
0040103C FF351C304000           push    dword ptr [40301Ch]
00401042 FF3518304000           push    dword ptr [403018h]
00401048 FF3514304000           push    dword ptr [403014h]
0040104E FF3510304000           push    dword ptr [403010h]
00401054 FF350C304000           push    dword ptr [40300Ch]
0040105A FF3508304000           push    dword ptr [403008h]
00401060 FF3504304000           push    dword ptr [403004h]
00401066 FF3500304000           push    dword ptr [403000h]
0040106C E811010000             call    fn_00401182


Title: Re: gluLookAt
Post by: Farabi on September 18, 2005, 02:57:24 AM
MichaelW:
Thanks, I will try it, I hope the prototype will not give an error because there are a new prototype with a new name.
Title: Re: gluLookAt
Post by: ninjarider on September 19, 2005, 06:53:56 PM
i dont understand y the gllookat would be such a hard function for u to use. it took a while to get it to work right but if u go to the glnormal thread i have and run my program. u would first have to step back some.

arrow keys do left right forward backwards
mouse looks left right up down
a,z move up and down
<, > roll left and right

the coding is a little hard in assembly i can give u the psuedo for it if u want.
Title: Re: gluLookAt
Post by: hitchhikr on September 19, 2005, 07:06:32 PM
I provided all necessary includes for the prototypes within the archive file.

Also, i'm a little bit busy with something right now but i'll be back very soon.
Title: Re: gluLookAt
Post by: Farabi on September 20, 2005, 01:50:31 AM
Quote from: ninjarider on September 19, 2005, 06:53:56 PM
i dont understand y the gllookat would be such a hard function for u to use. it took a while to get it to work right but if u go to the glnormal thread i have and run my program. u would first have to step back some.

arrow keys do left right forward backwards
mouse looks left right up down
a,z move up and down
<, > roll left and right

the coding is a little hard in assembly i can give u the psuedo for it if u want.

Yes it is very difficult and I dont have time to try it. I dont see your attachment but I see the picture.
So If I want to rotate the camera and move I only need to change vertex 3 like this

Quote
{x3, y3, z3} = {0,1,0} then the camera would be upright. any camera movement would move up
{x3, y3, z3} = {1,0,0} then the camera would be on its side. and camera movement would be to the right
{x3, y3, z3} = {0,-1,0} then the camera would be upside down. any camera movement would move down
{x3, y3, z3} = {-1,0,0} then the camera would be on its side again, but any camera movement would move the the left.

and change the position right? I still dont get it. But if you like to share your code to do movement dan rotate camera, I will appreciate it.

Im too dumb for this.
Title: Re: gluLookAt
Post by: ninjarider on September 21, 2005, 12:39:17 PM
ok.

to actually move it u would have to change x1, y1, z1. to move the camera left change x1. keep in mind that the camera will constantly look at x2, y2, z2. x3, y3, z3 just makes movement look really wierd so keep them to {0,1,0}. unless u get into making a fighter simulator then when u get to needing the roll u play with those 3.

hometown.aol.com\bloodycyborge\opengl.exe (http://hometown.aol.com\bloodycyborge\opengl.exe)

x = Sin(CameraAngle.y * PI / 180)
y = Sin(CameraAngle.x * PI / 180)
Z = Cos(CameraAngle.y * PI / 180)

With CameraPosition
    gluLookAt .x, .y, .Z, .x + x, .y + y, .Z + Z, Sin(CameraAngle.Z * PI / 180) * Z, Cos(CameraAngle.Z * PI / 180), Sin((360 - CameraAngle.Z) * PI / 180) * x
End With

thats what the function looks like in the program.
Title: Re: gluLookAt
Post by: Crocodile.Siberi@n on June 06, 2006, 04:16:12 PM
I've got the different problem.
When I use glLookAt to move camera it "shakes" the rendering image
It seems that camera is changing its distance to object (i've got like NFS camera spotting the car
Title: Re: gluLookAt
Post by: hitchhikr on June 07, 2006, 08:50:20 AM
It's possible that you're using something like camera position + FrameRate or similar code, if not then paste your code.