PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Need help creating advanced camera for Quark3D/PGL

pocketguest · 04 May 2006, 14:16 UTC
Hello guys,

Long time reader, 1st time poster :)

Need help with my camera.


I'm using Quark3D (Upscale PocketGL).

Here is old manual http://pierrel5.free.fr/Quark3D/Quark3D.html.


I can't figure out how to do a "flight sim camera".

I'm trying to create a camera like this one - www.codecolone.de/docs/camera2.html

I need it to turn around Z axis(roll) and around X axis (up/down).

so it's like a plane. The roll should be to the same side no matter where you are oriented.

Quark3D/PGL doesn't have gluLookAt() so I tried to create one and some rotation functions. But I can't get the cam to work correctly. It will roll but up/down movement will be at angle to screen..

The problem maybe beacuse Q3D/PGL use 4x3 matrix and somekind of different viewmatrix processing different from OpenGL (this is why tutorials like the one above don't work?)

Please help. Can't see what am I doing wrong :(

Would be nice to have a function for matrix based on 2 (up/down, roll) or 3 angles that could be used in a scene like below (demo9).
Would be nice to have something like CamRotate(ud, roll) that produces matrix you just load in to your object before doing any local transformations with them.

Even some PocketGL camera code would be appreciated! (See small code below at post #3)

He is my code below, it is modified demo9 from Quark3D.

I would really appreciate some help!

---------------------------------
Code:

// Draw textured geosphere + lightening effect // notes :
// The mesh is loaded from file using CImport::InitTL function.
// The init of the 2 mesh is done here 'manually' for tutorial reason, but could be done
// very shortly using Import.InitTL() function. (used in next demos)
// The demo9b.cpp do the same thing using this function.

#include "..\defines.h"
#ifdef DEMO9
#include "..\LibUtil\libutil.h"
#include "..\VGpu\quark.h"
#include "tgafile.h"
#include "..\AseToMsh\meshdata.h"
#include "import.h"
#include "..\Armlet\armlet.h"

CVGpu VGpu; // create a virtual gpu object
CTextureList TextureList; // use a list of textures
CImport Import; // CImport object used to load a mesh + texture from file

#define SPH_R0 200 // radius of sphere 0
#define SPH_R1 60 // radius of sphere 1

//new
struct Vector3D
{
int x,y,z;
};
Vector3D operator+(Vector3D v, Vector3D u) {
Vector3D res;
res.x = v.x + u.x;
res.y = v.y + u.y;
res.z = v.z + u.z;
return res;
}

Vector3D operator-(Vector3D v, Vector3D u) {
Vector3D res;
res.x = v.x - u.x;
res.y = v.y - u.y;
res.z = v.z - u.z;
return res;
}

Vector3D operator*( Vector3D v, int r)
{
Vector3D res;
res.x = ( v.x * r ) >> TRIGO_SHIFT;;
res.y = ( v.y * r ) >> TRIGO_SHIFT;;
res.z = ( v.z * r ) >> TRIGO_SHIFT;;
return res;
}

// CrossProduct v / u
Vector3D operator/(Vector3D v, Vector3D u) {
Vector3D res;

res.x = ( v.y * u.z - u.y * v.z ) >> TRIGO_SHIFT;
res.y = ( u.x * v.z - v.x * u.z ) >> TRIGO_SHIFT;
res.z = ( v.x * u.y - u.x * v.y ) >> TRIGO_SHIFT;

return res;
}
// camera.h
class CCamera
{
public:
Vector3D ViewDir;
Vector3D RightVector;
Vector3D UpVector;
Vector3D Position;

int RotatedX, RotatedY, RotatedZ;

CCamera();
void gluLookAt( Vector3D Position, Vector3D ViewPoint, Vector3D UpVector );
void Render ( void );

void RotateX ( int Angle );
void RotateY ( int Angle );
void RotateZ ( int Angle );
void MoveForward ( int Distance );
};

Vector3D FVector3D (int x, int y, int z) {
Vector3D tmp;
tmp.x = x;
tmp.y = y;
tmp.z = z;
return tmp;

}
//CMatrix gluLookAt( Position.x, Position.y, Position.z,

/***********/
CCamera::CCamera()
{
Position = FVector3D(0, 0, 0);
ViewDir = FVector3D(0, 0, -TRIGO_MUL);
RightVector = FVector3D(TRIGO_MUL, 0, 0);
UpVector = FVector3D(0, TRIGO_MUL, 0);

RotatedX = RotatedY = RotatedZ = 0;

}
void CCamera::Render( void )
{
// Vector3D ViewPoint = Position + ViewDir;
// gluLookAt( Position.x, Position.y, Position.z,
// ViewPoint.x, ViewPoint.y, ViewPoint.z,
// UpVector.x, UpVector.y, UpVector.z );

}

void CCamera::gluLookAt( Vector3D Position, Vector3D ViewPoint, Vector3D UpVector ) {
Vector3D f = ViewPoint - Position;

int tmpn[3];
tmpn[0] = f.x; tmpn[1] = f.y; tmpn[2] = f.z; Normalize(tmpn); f.x = tmpn[0]; f.y = tmpn[1]; f.z = tmpn[2];

Vector3D s = f / UpVector; // CrossProduct
tmpn[0] = s.x; tmpn[1] = s.y; tmpn[2] = s.z; Normalize(tmpn); s.x = tmpn[0]; s.y = tmpn[1]; s.z = tmpn[2];
Vector3D u = s / f; // CrossProduct
tmpn[0] = u.x; tmpn[1] = u.y; tmpn[2] = u.z; Normalize(tmpn); u.x = tmpn[0]; u.y = tmpn[1]; u.z = tmpn[2];

VGpu.CameraMatrix.LoadIdentity();

CMatrix CM;

CM.m[0]=s.x;
CM.m[1]=s.y;
CM.m[2]=s.z;

CM.m[3]=u.x;
CM.m[4]=u.y;
CM.m[5]=u.z;

CM.m[6]=-f.x;
CM.m[7]=-f.y;
CM.m[8]=-f.z;

CM.m[9]= 0;
CM.m[10]= 0;
CM.m[11]= 0;

VGpu.CameraMatrix.Mult(&CM);


UpVector.x = u.x; UpVector.y = u.y; UpVector.z = u.z;
ViewDir.x = f.x; ViewDir.y = f.y; ViewDir.z = f.z;
RightVector.x = s.x; RightVector.y = s.y; RightVector.z = s.z;

}

void CCamera::RotateX ( int Angle )
{
RotatedX += Angle;

// Rotate Viewdir around Right vector:
//ViewDir = ViewDir * COSINUS(Angle) + UpVector*SINUS(Angle);

ViewDir = FVector3D(0,0, -TRIGO_MUL) * COSINUS(Angle) + FVector3D(0,TRIGO_MUL,0)*SINUS(Angle);
// Normalize
int tmpn[3];
tmpn[0] = ViewDir.x; tmpn[1] = ViewDir.y; tmpn[2] = ViewDir.z; Normalize(tmpn); ViewDir.x = tmpn[0]; ViewDir.y = tmpn[1]; ViewDir.z = tmpn[2];

//now compute the new UpVector (CrossProduct)
//UpVector = (ViewDir / RightVector) * -TRIGO_MUL;
UpVector = (ViewDir / FVector3D(TRIGO_MUL, 0,0)) * -TRIGO_MUL; }

void CCamera::RotateY ( int Angle )
{
RotatedY += Angle;

// Rotate Viewdir around Up vector:
ViewDir = ViewDir * COSINUS(Angle) - RightVector*SINUS(Angle);
// Normalize
int tmpn[3];
tmpn[0] = ViewDir.x; tmpn[1] = ViewDir.y; tmpn[2] = ViewDir.z; Normalize(tmpn); ViewDir.x = tmpn[0]; ViewDir.y = tmpn[1]; ViewDir.z = tmpn[2];

//now compute the new UpVector (CrossProduct)
RightVector = (ViewDir / UpVector);

}

void CCamera::RotateZ ( int Angle )
{
RotatedZ += Angle;

// Rotate Viewdir around Right vector:
RightVector = RightVector * COSINUS(Angle) + UpVector*SINUS(Angle);
// Normalize
int tmpn[3];
tmpn[0] = RightVector.x; tmpn[1] = RightVector.y; tmpn[2] = RightVector.z; Normalize(tmpn); RightVector.x = tmpn[0]; RightVector.y = tmpn[1]; RightVector.z = tmpn[2];

//now compute the new UpVector (CrossProduct)
UpVector = (RightVector / ViewDir); // * -TRIGO_MUL;

}

CCamera Camera;

// names of texture to load
const char *TexName[2] = {"moon.tga", "Sun.tga"};

int DisplayMode; // used to change display mode (textured/untextured/wireframe)
int MessageTime; // manage time of displayed message
char *Message; // current message

// create a structure to work with 3D objects typedef struct {
CTriangleList Tl; // triangle list used to draw object

CMatrix Matrix; // a matrix to move object
int ARotations[3]; // first rotation
int BRotations[3]; // second rotation (for satellite sphere)

// face lightening
short *FNormalList; // contain normal of each face, used for lightening
} T3DObject;

T3DObject Obj3DList[2]; // use 2 spheres, one with 180 face, other one with 80 face

// main game init
int InitGame(void)
{
int i;
if (!VGpu.Init(CLIPZ_NEAR, CLIPZ_FAR, 70)) // init vgpu, Fov = 70 degree (2*PI = 360 degree)
return 0;

if (!TextureList.Alloc(2)) // alloc list for 2 textures
return 0;

// load 2 textures from file
for (i=0; i<2; i++)
{
char Path[80];
int x, y, Color;
unsigned char *Pixels;

strcpy(Path, "Tga24/");
strcat(Path, PICSTR(TexName[i]));

// load a tga file to define texture, and get untextured color (texture average RGB)
// using optional *AvgCol parameter of LoadTga function
if (!LoadTga(Path, &x, &y, &Pixels, &Color))
return 0;

// init the texture.
CTexture *T = &TextureList.Tex[i];
if (!T->Init(Pixels, x, y, Path))
return 0;

T->UtColor = Color; // define average color to display in untextured mode
}

// -------------------------------------------------
// init object 0, geosphere with 92 vertex/180 faces

// load a sphere mesh from file
if (!Import.FileLoad("Mesh/Sph180.msh"))
return 0;

CTriangleList *Tl = &Obj3DList[0].Tl;

// define a vertex and index format to draw sphere using DrawTriangleList() function
int VertexFormat = VF_XYZ; // store vertex position only
int IndexFormat = IF_ABC | IF_I | IF_UV; // store vertex index + face intensity + vertex uv

// check vertex-index format compatibility and alloc memory for list
if (!Tl->Alloc(VertexFormat, Import.md.VPosListSize, IndexFormat, Import.md.IndexListSize))
return 0;

// init the vertex position. note: default scale of data objects in Geom.cpp is 256
int j, k;
j=0;
for (i=0; i<Import.md.VPosListSize; i++)
{
short Pos[3];
Pos[0] = (Import.md.VPosList[j] * SPH_R0) >> 8;
Pos[1] = (Import.md.VPosList[j+1] * SPH_R0) >> 8;
Pos[2] = (Import.md.VPosList[j+2] * SPH_R0) >> 8;
Tl->SetXYZ(i, Pos); // store position in list
j+=3;
}

// init the face uv list. note: uv of initial sphere datas are already scaled by UV_MUL
j=0;
k=0;
for (i=0; i<Import.md.IndexListSize; i++)
{
Tl->SetABC(i, &Import.md.IndexList[j]); // set vertex index
Tl->SetI(i, 128); // define initial intensity
Tl->SetUV(i, &Import.md.UvList[k]); // 3*uv
j+=3;
k+=6;
}

Import.Delete(); // free memory allocated by Import

// build command list
if (!Tl->BuildCmdList(NULL, 0)) // pass null if same rendering state used for all faces
return 0;

// alloc memory to store face normal to light geosphere 0
short *NList = (short *)malloc(Tl->IndexListSize*3*sizeof(short));
if (!NList)
return 0;
Obj3DList[0].FNormalList = NList; // set ptr into object

// init face normal list
for (i=0; i<180; i++)
{
int ABC[3]; // vertex index
Tl->GetABC(i, ABC);

int A[3], B[3], C[3]; // vertex position
Tl->GetXYZ(ABC[0], A);
Tl->GetXYZ(ABC[1], B);
Tl->GetXYZ(ABC[2], C);

int N[3]; // normal to face
DefUNormal(A, B, C, N); // define a normal vector to face (not normalized)
Normalize(N); // normalize vector (to get norm = TRIGO_MUL)
NList[0] = N[0]; // store result in list
NList[1] = N[1];
NList[2] = N[2];
NList += 3;
}

// -----------------------------------------------------------------
// init object 1, geosphere with 42 Vertex/80 faces, radius = SPH_R1
// store intensity into vertex, and uv into faces

// load a sphere mesh from file
if (!Import.FileLoad("Mesh/Sph80.msh"))
return 0;

Tl = &Obj3DList[1].Tl;

// define a vertex and index format to draw sphere 1
VertexFormat = VF_XYZ | VF_I; // store vertex position + intensity
IndexFormat = IF_ABC | IF_UV; // store vertex index + vertex uv

// alloc memory for triangle list
if (!Tl->Alloc(VertexFormat, Import.md.VPosListSize, IndexFormat, Import.md.IndexListSize))
return 0;

// init the vertex position. use scale = SPH_R1
j=0;
for (i=0; i<Import.md.VPosListSize; i++)
{
short Pos[3];
Pos[0] = (Import.md.VPosList[j] * SPH_R1) >> 8;
Pos[1] = (Import.md.VPosList[j+1] * SPH_R1) >> 8;
Pos[2] = (Import.md.VPosList[j+2] * SPH_R1) >> 8;
Tl->SetXYZ(i, Pos); // store position in list
Tl->SetI(i, 128); // define initial intensity
j+=3;
}

// init the face uv list. note: uv of initial sphere datas are already scaled by UV_MUL
j=0;
k=0;
for (i=0; i<Import.md.IndexListSize; i++)
{
Tl->SetABC(i, &Import.md.IndexList[j]); // set vertex index
Tl->SetUV(i, &Import.md.UvList[k]);
j+=3;
k+=6;
}

Import.Delete(); // free memory allocated by Import

// build command list
if (!Tl->BuildCmdList(NULL, 1)) // pass null if same rendering state used for all faces
return 0;

// messages
DisplayMode = 0; // used to change display mode (textured/untextured/wireframe)
MessageTime = 0; // manage time of displayed message
Message = NULL; // no message

// reserve some working memory for internal work of DrawTriangleList() function.
int MaxVertex;

if (Obj3DList[0].Tl.VertexListSize > Obj3DList[1].Tl.VertexListSize)
MaxVertex = Obj3DList[0].Tl.VertexListSize;
else
MaxVertex = Obj3DList[1].Tl.VertexListSize;

if (!VGpu.SetWorkMemory(MaxVertex, 0)) // max triangle list size is 92 vertex, 0 sorted faces (alpha) are used
return 0;

return 1; // init success
}

// scan key to change rendering mode
void ScanKeyboard(void)
{

if (ARMData->Keyboard.KeyPressedId)
{

if (ARMData->Keyboard.KeyPressed[ARMData->CfgData.KeyCode[KEY_ACTION]])
{
ARMData->Keyboard.KeyPressed[ARMData->CfgData.KeyCode[KEY_ACTION]] = 0;
//fire
}
if (ARMData->Keyboard.KeyPressedId == ARMData->CfgData.KeyCode[KEY_LEFT])
{
Camera.RotateZ(100);
}
else
if (ARMData->Keyboard.KeyPressedId == ARMData->CfgData.KeyCode[KEY_RIGHT])
{
Camera.RotateZ(-100);
}
else
if (ARMData->Keyboard.KeyPressedId == ARMData->CfgData.KeyCode[KEY_UP])
{
Camera.RotateX(-100);
}
else
if (ARMData->Keyboard.KeyPressedId == ARMData->CfgData.KeyCode[KEY_DOWN])
{
Camera.RotateX(100);
}
else

if (ARMData->Keyboard.KeyPressedId == ARMData->CfgData.KeyCode[KEY_D])
{
// return 0;
}

ARMData->Keyboard.KeyPressedId = 0;
}
}

// main game loop, time is passed, must return 0 to quit int LoopGame(void) {
ScanKeyboard(); // something to change ?

T3DObject *Sph0, *Sph1;
Sph0 = &Obj3DList[0]; // fixed sphere
Sph1 = &Obj3DList[1]; // satellite sphere

//VGpu.CameraMatrix.LoadIdentity();
//Camera.Render();

Camera.gluLookAt( Camera.Position, Camera.Position + Camera.ViewDir, Camera.UpVector );

// ---------------------
// set sphere 0 position
Sph0->Matrix.LoadIdentity(); // init matrix

Sph0->Matrix.Mult(&VGpu.CameraMatrix);

//Sph0->Matrix.Load(&VGpu.CameraMatrix); //LoadIdentity(); // init matrix

Sph0->Matrix.Translate(0, 0, -300); // define translation on -z axis (camera look on -z direction)
//Sph0->Matrix.RotateX(Sph0->ARotations[0]); // define xyz ARotations
//Sph0->Matrix.RotateY(Sph0->ARotations[1]);
//Sph0->Matrix.RotateZ(Sph0->ARotations[2]);

// update Rotations angles
Sph0->ARotations[0] += 0;
Sph0->ARotations[1] += 0;
Sph0->ARotations[2] += 0;

// ---------------------
// set sphere 1 position
Sph1->Matrix.Load(&VGpu.CameraMatrix); //LoadIdentity();
Sph1->Matrix.Translate(0, 0, -300); // goto big sphere position
Sph1->Matrix.RotateX(Sph1->ARotations[0]); // define rotation around big sphere
Sph1->Matrix.RotateY(Sph1->ARotations[1]);
Sph1->Matrix.RotateZ(Sph1->ARotations[2]);
Sph1->Matrix.Translate(SPH_R0/2 + 60, 0, 0); // translate around big sphere (radius + 60)

// update Rotations angles
Sph1->ARotations[0] += 0;
Sph1->ARotations[1] += 0;
Sph1->ARotations[2] += 0;

// ---------------------------------------------------------------
// define a light power for sphere 1. use frame counter to animate
int i;
int Phase = (VGpu.FrameCounter*ANGLE2PI) >> 4; // 1 complete cycle for 16 frames
int Power = TRIGO_MUL + SINUS(Phase); // 0 -> 2*TRIGO_MUL variation
Power = 80 + ((Power*175) >> (TRIGO_SHIFT + 1)); // define min = 80 + [0..175] range in variation

// update vertex intensity of satellite sphere
CTriangleList *Tl = &Sph1->Tl;
unsigned short *IList = (unsigned short *)&Tl->VertexList[Tl->ViOfs]; // point to first intensity in vertex list
for (i=0; i<42; i++)
{
*IList = Power;
IList += Tl->VertexStride;
}

// ---------------------------------------------------------------
// define lightening intensity on sphere 0 using sphere 1 position
int *A = Sph1->Matrix.Pos(); // get position of sphere 1
int *B = Sph0->Matrix.Pos(); // get position of sphere 0

// light direction
int AB[3]; // light direction
AB[0] = B[0] - A[0];
AB[1] = B[1] - A[1];
AB[2] = B[2] - A[2];
Normalize(AB); // normalize

Tl = &Sph0->Tl;
IList = &Tl->IndexList[Tl->IiOfs]; // get ptr on list intensity of 1st face in triangle list (IF_ABCIUV format used)
short *NList = Sph0->FNormalList; // ptr on normal list

#if 0
// slowest method: rotate each normal vector of object to light
for (i=0; i<180; i++)
{
int N[3];
N[0] = NList[0];
N[1] = NList[1];
N[2] = NList[2];

Sph0->Matrix.RotateVector(N, N); // perform only rotation using sphere 0 matrix (ignore translations)
#else
// fastest method: inverse rotate only light direction, then do not need to rotate each face normal of object to light
Sph0->Matrix.InvRotateVector(AB, AB); // perform inverse rotation using sphere 0 transposed matrix
for (i=0; i<180; i++)
{
int N[3];
N[0] = NList[0];
N[1] = NList[1];
N[2] = NList[2];

#endif
int Dot = AB[0]*N[0] + AB[1]*N[1] + AB[2]*N[2]; // dot product

int Intensity = 100; // define base 'unlighted' intensity
if (Dot < 0) // triangle is oriented to light
{
int di = -Dot >> (TRIGO_SHIFT*2 - 8); // devide by norm of NList[i] + norm of AB, and scale result by 256, this give ligt effect
Intensity += (di*Power*155) >> 16;

// saturate to avoid loop (ex: 257 will define (257 & 0xff) -> intensity = 1)
if (Intensity > 255)
Intensity = 255;
}

*IList = Intensity;

IList += Tl->IndexStride;
NList += 3;
}

// ----
// draw
VGpu.ViewMatrix = &Sph0->Matrix; // change VGpu view matrix (default is &VGpu.Matrix)
VGpu.DrawTriangleList(&Sph0->Tl, &TextureList); // note: return value of DrawTriangleList ignored here

VGpu.ViewMatrix = &Sph1->Matrix;
VGpu.DrawTriangleList(&Sph1->Tl, &TextureList);


VGpu.PrintFps(); // display framerate
return !ARMData->Mouse.LButtonDown; // loop util click/tap on screen occur
}

// blit datas into video memory, and clear virtual screen in dark blue void BlitScreen(void) {
VGpu.FlushFB(COLOR_RGB(0, 0, 64));
}

// free memory
void EndGame(void)
{
Obj3DList[0].Tl.Delete();
free(Obj3DList[0].FNormalList);
Obj3DList[1].Tl.Delete();
TextureList.Delete();
VGpu.Delete();
}
#endif // DEMOx
joshbu [MSFT] · 04 May 2006, 16:19 UTC
Whoa. Lots of code.

Is your 3d system right or left handed? The formulation of LookAt is different between the two.
pocketguest · 04 May 2006, 16:42 UTC
Not sure, my system is Quark3D which is a version of PocketGL by the same author (Pierre). The only things I added is to that demo9.cpp is couple key handling lines and gluLookAt, Rotate etc..

So it's a standard Quark3D.

Thanks for help.

joshbu [MSFT] wrote:Whoa. Lots of code.

Is your 3d system right or left handed? The formulation of LookAt is different between the two.
pocketguest · 05 May 2006, 00:18 UTC
Hmm, tried to redo demo10 from PocketGL even, can't figure out how to do it correctly. ( //*** - new code )

The demo (FPS) uses only DefRotateY to turn around UP axis, I need to add RotateZ to roll.

That code below works, but the direction vector get's out of touch with the camera center..

---
Code:

..
CMatrix44 M;
Vector4s DeltaMove;

// update work of fixed lights
for (i=0; i<FixedLightCount; i++)
FixedLightList[i].Activate();

// rotations
PlayerRot.x += 0;
PlayerRot.y += (RotateSpeed*dTimeFilter) >> 9;
PlayerRot.z += (RotateSpeedZ*dTimeFilter) >> 9; //***


M.DefRotateY(PlayerRot.y); // define Y rotation matrix
M.RotateZ(PlayerRot.z); //*** define Y rotation matrix

// forward move
DeltaMove.Init(M.Dir()); // get forward direction vector
int Fwd = (ForwardSpeed*dTimeFilter) >> 9;
PlayerPos.x += (DeltaMove.x * Fwd) >> COS_SIN_SHIFT; // unit vector is scaled
PlayerPos.y += (DeltaMove.y * Fwd) >> COS_SIN_SHIFT; //*** unit vector is scaled
PlayerPos.z += (DeltaMove.z * Fwd) >> COS_SIN_SHIFT;

// straf move
DeltaMove.Init(M.Left()); // get left direction vector
PlayerPos.x += (DeltaMove.x * StrafSpeed) >> COS_SIN_SHIFT;
PlayerPos.y += (DeltaMove.y * StrafSpeed) >> COS_SIN_SHIFT; //*** unit vector is scaled
PlayerPos.z += (DeltaMove.z * StrafSpeed) >> COS_SIN_SHIFT;

MatrixStack.PushMatrix();

// define scene move as inverse of camera move (camera is always fixed at origin and look on -z)
MatrixStack.CurrentMatrix->Pos()->Init(0, 0, 0);
MatrixStack.CurrentMatrix->DefRotateY(-PlayerRot.y);
MatrixStack.CurrentMatrix->RotateZ(-PlayerRot.z); //***



MatrixStack.CurrentMatrix->Translate(-PlayerPos.x, -PlayerPos.y, -PlayerPos.z);

// draw fixed objects with BSP
// the renderer states (HRS, ZCorrection), are affected by this function
// so you have to reset state to requested value if you wand to draw other objects (mobile objects)
Bsp.DrawFixedObjectsSubDiv();

MatrixStack.PopMatrix();
pocketguest: You can use the code tags (just click the button at the top) in order to format and colorify your code-- makes it a bit easier to read.