ARToolKit | Mailing List Archive |
![]() |
From: | =?ISO-8859-1?Q?=22Sandra_L=F6ffler=22?= <sandra.loeffler@g .....> | Received: | Aug 4, 2004 |
To | artoolkit@h .................. | ||
Subject: | Change position of virtual camera | ||
Hello, I'm implementing shadow maps in the ARToolkit. For this purpose it is necessary to render the scene from the light's point of view. So I have to move the camera at lightposition. I tried it with glLookAt. Here is some code. First I define the projection and modelviewmatrix. glPushMatrix(); glLoadIdentity(); gluPerspective(90.0f,1,1, 1000); glGetFloatv(GL_PROJECTION_MATRIX, lightFrustumMatrix); glLoadIdentity(); gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0, 0, 0, 0, 0, -1); glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); glPopMatrix(); Then I move the camera: glMatrixMode(GL_PROJECTION); glLoadMatrixf(lightFrustumMatrix); glMatrixMode(GL_MODELVIEW); glLoadMatrixf(lightViewMatrix); Now I should see the scene from lightposition. But it doesn't work. Where is the problem? I also have the problem to place the objects relative to the markers. To do this i have the transformationmatrix which I get with arGetTransMat(...) and argConvGlpara(...) before moving the camera at lightposition. So I have to combine the objects transformationmatrix with the lightViewMatrix. But I'm not sure how to do this. I hope my question is clear and anybody can help me. thanks in advance Sandra -- NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler! GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl |
From: | Mathis Ahrens <Mathis.Ahrens@g .....> | Received: | Aug 5, 2004 |
To | artoolkit@h .................. | ||
Subject: | Re: Change position of virtual camera | ||
Hi Sandra, Sandra Löffler schrieb: >I'm implementing shadow maps in the ARToolkit. >For this purpose it is necessary to render the scene from the light's point >of view. >So I have to move the camera at lightposition. > >I tried it with glLookAt. Here is some code. > >First I define the projection and modelviewmatrix. > > No, you don't. >glPushMatrix(); > glLoadIdentity(); > gluPerspective(90.0f,1,1, 1000); > glGetFloatv(GL_PROJECTION_MATRIX, lightFrustumMatrix); > > glLoadIdentity(); > gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0, 0, 0, 0, 0, -1); > glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); >glPopMatrix(); > > If this is one complete section in your code, you are working on one single matrix only. Try glMatrixMode to switch to a specific matrix before you do glLoadIdentity(). Like so: glMatrixMode(GL_MODELVIEW); glLoadIdentity(); gluPerspective(90.0f,1,1, 1000); glGetFloatv(GL_PROJECTION_MATRIX, lightFrustumMatrix); glMatrixMode(GL_PROJECTION); glLoadIdentity(); gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0, 0, 0, 0, 0, -1); glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); If you need to keep the original matrices, you obviously need to push and pop two times, too. > >Then I move the camera: > >glMatrixMode(GL_PROJECTION); >glLoadMatrixf(lightFrustumMatrix); > >glMatrixMode(GL_MODELVIEW); >glLoadMatrixf(lightViewMatrix); > > >Now I should see the scene from lightposition. But it doesn't work. Where is >the problem? > >I also have the problem to place the objects relative to the markers. To do >this i have the transformationmatrix which I get with arGetTransMat(...) and >argConvGlpara(...) before moving the camera at lightposition. > > > I am not sure if I understand you here. The Objects appear on the markers and you want to move them? How about glTranslatef then? The examples in ARToolkit do just that... >So I have to combine the objects transformationmatrix with the >lightViewMatrix. But I'm not sure how to do this. > > Or glMultMatrix ? Cheers, mathis |
From: | =?ISO-8859-1?Q?=22Sandra_L=F6ffler=22?= <sandra.loeffler@g .....> | Received: | Aug 16, 2004 |
To | Philip Lamb <phil@r .........> | ||
Subject: | Re: Change position of virtual camera | ||
thanks for your answer. I tried it, but it doesn't work correctly. My problem is that i don't know how to position my objects relativ to the marker after I moved the camera at lightposition. I get my transformationmatrix "gl_para". arGetTransMat(&m_mymarkerinfo, m_center, m_width, m_trans); // load the camera transformation matrix argConvGlpara(m_trans, gl_para); This Matrix I use to position my objects relativ to the marker. But I'm not sure how I have to do this. My problem is, that I don't see my objects from light's point of view. Here is my code. glMatrixMode(GL_PROJECTION); glPushMatrix(); glLoadIdentity(); gluPerspective(90.0, 1.0, 1.0, 1000.0); glMatrixMode(GL_MODELVIEW); glPushMatrix(); glLoadIdentity(); gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0.0, 0.0, 0.0, 0.0, 0.0, -1.0); glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); //Here I draw my Objects. glPushMatrix(); glMultMatrixf( gl_para); renderObj(); glPopMatrix(); glPopMatrix(); glMatrixMode(GL_PROJECTION); glPopMatrix(); glMatrixMode(GL_MODELVIEW); How does I have to combine the lightViewMatrix with the gl_para-matrix? thanks Sandra > At 5:17 PM +0200 4/8/04, Sandra Löffler wrote: > >Hello, > > > >I'm implementing shadow maps in the ARToolkit. > >For this purpose it is necessary to render the scene from the light's > point > >of view. > >So I have to move the camera at lightposition. > > > >I tried it with glLookAt. Here is some code. > > > >First I define the projection and modelviewmatrix. > > > >glPushMatrix(); > > glLoadIdentity(); > > gluPerspective(90.0f,1,1, 1000); > > glGetFloatv(GL_PROJECTION_MATRIX, lightFrustumMatrix); > > > > glLoadIdentity(); > > gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0, 0, 0, 0, 0, -1); > > glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); > >glPopMatrix(); > > > > > >Then I move the camera: > > > >glMatrixMode(GL_PROJECTION); > >glLoadMatrixf(lightFrustumMatrix); > > > >glMatrixMode(GL_MODELVIEW); > >glLoadMatrixf(lightViewMatrix); > > Sandra, > > As Mathis has said, you are only changing one matrix (whatever was > set at the top of your code) but you are retreiving the values of two > matrices (modelview and projection.) In general for maximum > efficiency you should avoid glLoadMatrix unless there's no other way. > > Here's a better way: > > glMatrixMode(GL_PROJECTION); > glPushMatrix(); > glLoadIdentity(); > gluPerspective(90.0, 1.0, 1.0, 1000.0); > glMatrixMode(GL_MODELVIEW); > glPushMatrix(); > glLoadIdentity(); > gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0.0, 0.0, 0.0, 0.0, > 0.0, -1.0); > > (do drawing here.) > > glPopMatrix(); > glMatrixMode(GL_PROJECTION); > glPopMatrix(); > glMatrixMode(GL_MODELVIEW); > > That should work, providing your lightpos[] array has sensible values > that are far enough away from the geometry that you're drawing, and > that your geometry is located near the origin, which is where you're > looking. Also a small note that gluPerspective and gluLookAt take > doubles, not floats - I removed the "f" from the constants. > > Regards, > > Phil. > -- NEU: WLAN-Router für 0,- EUR* - auch für DSL-Wechsler! GMX DSL = supergünstig & kabellos http://www.gmx.net/de/go/dsl |
From: | Philip Lamb <phil@e ..........> | Received: | Aug 19, 2004 |
To | =?iso-8859-1?Q?=22Sandra_L=F6ffler=22?= <sandra.loeffler@g .....> | ||
Subject: | Re: Change position of virtual camera | ||
Sandra, Shadow mapping is a two-pass approach. So the first pass you would position your camera at the position of your light using gluLookAt and then render your scene. You shouldn't be using the virtual camera matrix from ARToolKit in the first pass at all. In the second pass, you'd use your marker to define the origin of your coordinate system, you'd position your virtual camera using arGetTransMat + argConvGlpara, + glLoadMatrix, and then render your scene (making use of the shadow map via whatever technique is appropriate.) Regards, Phil. At 9:23 PM +0200 16/8/04, Sandra Löffler wrote: >thanks for your answer. > >I tried it, but it doesn't work correctly. > >My problem is that i don't know how to position my objects relativ to the >marker after I moved the camera at lightposition. > >I get my transformationmatrix "gl_para". > >arGetTransMat(&m_mymarkerinfo, m_center, m_width, m_trans); > >// load the camera transformation matrix >argConvGlpara(m_trans, gl_para); > >This Matrix I use to position my objects relativ to the marker. > >But I'm not sure how I have to do this. My problem is, that I don't see my >objects from light's point of view. > > >Here is my code. > >glMatrixMode(GL_PROJECTION); >glPushMatrix(); >glLoadIdentity(); >gluPerspective(90.0, 1.0, 1.0, 1000.0); >glMatrixMode(GL_MODELVIEW); >glPushMatrix(); >glLoadIdentity(); >gluLookAt(lightPos[0], lightPos[1], lightPos[2], 0.0, 0.0, 0.0, 0.0, >0.0, -1.0); >glGetFloatv(GL_MODELVIEW_MATRIX, lightViewMatrix); > >//Here I draw my Objects. > >glPushMatrix(); >glMultMatrixf( gl_para); >renderObj(); >glPopMatrix(); > >glPopMatrix(); >glMatrixMode(GL_PROJECTION); >glPopMatrix(); >glMatrixMode(GL_MODELVIEW); > > >How does I have to combine the lightViewMatrix with the gl_para-matrix? > >thanks Sandra -- Philip Lamb Research Student, Human Interface Technology Laboratory New Zealand, University of Canterbury, Christchurch, NZ. +64 3 3642987 x3070 |