Re: Model View Transformation

"Mohan Parthasarathy" <[email protected]> Wed, 15 Oct 2008 15:15:24 -0800
Newsgroups gmane.games.devel.opengl
Organization Fat City Network Services, San Diego, California
Message-ID <[email protected]>
------=_Part_7029_13765928.1224108934306
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

On Wed, Oct 15, 2008 at 11:45 AM, Uday Verma <[email protected]> wrote:

> 1) You're seeing the back face of the back face of your cube.  I am not
> sure exactly why this is happening .. but may be your eye is right on the
> near plane.  Paste some code and we can analyze it better.
>

I simplified it..

int DrawGLScene(GLvoid)
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrtho(-3.0, 3.0, -3.0,3.0, -3.0,3.0);

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glTranslatef(0.0f, 0.0f, 2.1f);

glBegin(GL_QUADS);
glColor3f(0.0f,1.0f,0.0f);
glVertex3f(1.0f,1.0f,-1.0f); /*Top*/
glVertex3f(-1.0f, 1.0f,-1.0f);
glVertex3f(-1.0f, 1.0f, 1.0f);
glVertex3f( 1.0f,1.0f,1.0f);
/* Other Vertices with different colors */
glEnd();
}

My front face is red and back face is yellow. When i try value 2.1f and
greater, i see the yellow face. Anything less than that i see the red face.
Why is it so ?


> 2) View volume is defined in eye-space so the direction of camera doesn't
> matter.  View volume will always be aligned with where the camera is
> looking.  The camera is too far, you are correct.  The far clipping plane is
> closer to you than the box you're trying to view.
>

Ah!  so, if i am at position (x, y, z) i can see everything in
front/back/sides everything right ?

I draw a unit cube around the origin with 0.5 units on either side of the x
and y axis, and the camera if left at origin (by default). I am able to see
the cube still (assume default glortho). Red book says that you have to move
away from the origin at least to view. But going by the above explanation,
you should be able to see whatever is in the view at (0,0)

thanks
mohan


>
>
> On Wed, Oct 15, 2008 at 1:10 PM, Mohan Parthasarathy <[email protected]>wrote:
>
>> Hi,
>>
>> I am able to see the cube. So, my view volume should be right, no ? I was
>> mainly trying to understand my observations as to what happens when i move
>> around the camera ? What do you mean by "in the direction of the camera" ?
>> Can you explain ?
>>
>> thx
>> mohan
>>
>>
>>
>> On Tue, Oct 14, 2008 at 6:50 PM, priyadarshi <[email protected]>wrote:
>>
>>> You are not setting up the projection matrix correctly. Both the near
>>> plane and far plane( of the view volume) should be located in the
>>> direction in which camera is looking.
>>> All objects outside the view volume will be culled so make sure the cube
>>> is inside the view volume.
>>>
>>> > Hi,
>>> >
>>> > I am drawing a cube (2 units on all sides)  that extends from -1 to 1
>>> on Z
>>> > axis. I have defined a view volume (parallel projection) that covers 3
>>> > units
>>> > on all sides (glOrtho (-3.0, 3.0, -3.0,3.0,-3.0,3.0). The cube faces
>>> are
>>> > differently colored so that i know what faces i am looking
>>> > at. The camera by default is at (0,0,0).
>>> >
>>> > 1) glTranslate on Z axis with 0.0, 1.0 and 2.0, i see the front face.
>>> If i
>>> > move greater than 2.0  units, i see the back face. I am unable to
>>> explain
>>> > this. Isn't the camera pointing towards the -Z axis at the begninning ?
>>> > Then
>>> > why am i seeing the front face. Then when i cross 2 units, i see the
>>> back
>>> > face. I am unable to understand this. To see the front face, don't i
>>> have
>>> > to
>>> > be in front of the cube i.e something like -1.1 ? Also, for seeing the
>>> > back
>>> > face, don't i have to move forward at least 1.1 and then turn around ?
>>> I
>>> > am
>>> > confused.
>>> >
>>> > 2) glTranslate on Z axis with values >  4.0 or -4.0, i don't see the
>>> cube.
>>> > I
>>> > can see that the camera/viewpoint is  too far. What is too far ? How do
>>> i
>>> > know that i have gone too far without trying different values ?
>>> >
>>> >
>>> > Thanks for any help.
>>> > mohan
>>> >
>>>
>>> -----
>>> FAQ and OpenGL Resources at:
>>>  http://www.geocities.com/SiliconValley/Hills/9956/OpenGL
>>>
>>> --
>>> Author: priyadarshi
>>>  INET: [email protected]
>>>
>>> Fat City Hosting, San Diego, California -- http://www.fatcity.com
>>> ---------------------------------------------------------------------
>>> To REMOVE yourself from this mailing list, send an E-Mail message
>>> to: [email protected] (note EXACT spelling of 'ListGuru') and in
>>> the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
>>> (or the name of mailing list you want to be removed from).  You may
>>> also send the HELP command for other information (like subscribing).
>>>
>>
>>
>
>
> --
> Uday
> http://soundc.de/
>

------=_Part_7029_13765928.1224108934306
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

<div dir="ltr"><br><br><div class="gmail_quote">On Wed, Oct 15, 2008 at 11:45 AM, Uday Verma <span dir="ltr">&lt;<a href="mailto:[email protected]">[email protected]</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
<div dir="ltr">1) You&#39;re seeing the back face of the back face of your cube.&nbsp; I am not sure exactly why this is happening .. but may be your eye is right on the near plane.&nbsp; Paste some code and we can analyze it better.</div>
</blockquote><div><br>I simplified it..<br>&nbsp;<br></div><div>int DrawGLScene(GLvoid)<br>
{<br>
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);		 <br>
	glMatrixMode(GL_PROJECTION);<br>
	glLoadIdentity();<br>
	glOrtho(-3.0, 3.0, -3.0,3.0, -3.0,3.0);<br>
<br>
        glMatrixMode(GL_MODELVIEW);<br>
	glLoadIdentity();<br>
	glTranslatef(0.0f, 0.0f, 2.1f);<br>
<br>
	glBegin(GL_QUADS);<br>
        glColor3f(0.0f,1.0f,0.0f);			 <br>
        glVertex3f(1.0f,1.0f,-1.0f); /*Top*/				 <br>
        glVertex3f(-1.0f, 1.0f,-1.0f);					<br>
        glVertex3f(-1.0f, 1.0f, 1.0f);<br>
        glVertex3f( 1.0f,1.0f,1.0f);	<br>
        /* Other Vertices with different colors */<br>
        glEnd();<br>
} <br><br>My front face is red and back face is yellow. When i try value 2.1f and
greater, i see the yellow face. Anything less than that i see the red
face. Why is it so ?<br>
<br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><br>2) View volume is defined in eye-space so the direction of camera doesn&#39;t matter.&nbsp; View volume will always be aligned with where the camera is looking.&nbsp; The camera is too far, you are correct.&nbsp; The far clipping plane is closer to you than the box you&#39;re trying to view.<div>
<div></div><div class="Wj3C7c"></div></div></div></blockquote><div><br>Ah!&nbsp; so, if i am at position (x, y, z) i can see everything in front/back/sides everything right ?<br>&nbsp;<br>I draw a unit cube around the origin with 0.5 units on either side of the x and y axis, and the camera if left at origin (by default). I am able to see the cube still (assume default glortho). Red book says that you have to move away from the origin at least to view. But going by the above explanation, you should be able to see whatever is in the view at (0,0)<br>
<br>thanks<br>mohan<br><br></div><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;"><div dir="ltr"><div><div class="Wj3C7c"><br>
<br><br><div class="gmail_quote">On Wed, Oct 15, 2008 at 1:10 PM, Mohan Parthasarathy <span dir="ltr">&lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">

<div dir="ltr">Hi,<br><br>I am able to see the cube. So, my view volume should be right, no ? I was mainly trying to understand my observations as to what happens when i move around the camera ? What do you mean by &quot;in the direction of the camera&quot; ? Can you explain ?<br>


<br>thx<br><font color="#888888">mohan</font><div><div></div><div><br><br><br><div class="gmail_quote">On Tue, Oct 14, 2008 at 6:50 PM, priyadarshi <span dir="ltr">&lt;<a href="mailto:[email protected]" target="_blank">[email protected]</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">
You are not setting up the projection matrix correctly. Both the near<br>
plane and far plane( of the view volume) should be located in the<br>
direction in which camera is looking.<br>
All objects outside the view volume will be culled so make sure the cube<br>
is inside the view volume.<br>
<div><div></div><div><br>
&gt; Hi,<br>
&gt;<br>
&gt; I am drawing a cube (2 units on all sides) &nbsp;that extends from -1 to 1 on Z<br>
&gt; axis. I have defined a view volume (parallel projection) that covers 3<br>
&gt; units<br>
&gt; on all sides (glOrtho (-3.0, 3.0, -3.0,3.0,-3.0,3.0). The cube faces are<br>
&gt; differently colored so that i know what faces i am looking<br>
&gt; at. The camera by default is at (0,0,0).<br>
&gt;<br>
&gt; 1) glTranslate on Z axis with 0.0, 1.0 and 2.0, i see the front face. If i<br>
&gt; move greater than 2.0 &nbsp;units, i see the back face. I am unable to explain<br>
&gt; this. Isn&#39;t the camera pointing towards the -Z axis at the begninning ?<br>
&gt; Then<br>
&gt; why am i seeing the front face. Then when i cross 2 units, i see the back<br>
&gt; face. I am unable to understand this. To see the front face, don&#39;t i have<br>
&gt; to<br>
&gt; be in front of the cube i.e something like -1.1 ? Also, for seeing the<br>
&gt; back<br>
&gt; face, don&#39;t i have to move forward at least 1.1 and then turn around ? I<br>
&gt; am<br>
&gt; confused.<br>
&gt;<br>
&gt; 2) glTranslate on Z axis with values &gt; &nbsp;4.0 or -4.0, i don&#39;t see the cube.<br>
&gt; I<br>
&gt; can see that the camera/viewpoint is &nbsp;too far. What is too far ? How do i<br>
&gt; know that i have gone too far without trying different values ?<br>
&gt;<br>
&gt;<br>
&gt; Thanks for any help.<br>
&gt; mohan<br>
&gt;<br>
<br>
</div></div>-----<br>
FAQ and OpenGL Resources at:<br>
 &nbsp;<a href="http://www.geocities.com/SiliconValley/Hills/9956/OpenGL" target="_blank">http://www.geocities.com/SiliconValley/Hills/9956/OpenGL</a><br>
<br>
--<br>
Author: priyadarshi<br>
 &nbsp;INET: <a href="mailto:[email protected]" target="_blank">[email protected]</a><br>
<br>
Fat City Hosting, San Diego, California -- <a href="http://www.fatcity.com" target="_blank">http://www.fatcity.com</a><br>
---------------------------------------------------------------------<br>
To REMOVE yourself from this mailing list, send an E-Mail message<br>
to: <a href="mailto:[email protected]" target="_blank">[email protected]</a> (note EXACT spelling of &#39;ListGuru&#39;) and in<br>
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L<br>
(or the name of mailing list you want to be removed from). &nbsp;You may<br>
also send the HELP command for other information (like subscribing).<br>
</blockquote></div><br></div></div></div>
</blockquote></div><br><br clear="all"><br></div></div>-- <br>Uday<br><a href="http://soundc.de/" target="_blank">http://soundc.de/</a><br>
</div>
</blockquote></div><br></div>

------=_Part_7029_13765928.1224108934306--
----- 
FAQ and OpenGL Resources at:
  http://www.geocities.com/SiliconValley/Hills/9956/OpenGL

-- 
Author: Mohan Parthasarathy
  INET: [email protected]

Fat City Hosting, San Diego, California -- http://www.fatcity.com
---------------------------------------------------------------------
To REMOVE yourself from this mailing list, send an E-Mail message
to: [email protected] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB OPENGL-GAMEDEV-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).