本文整理汇总了C++中TVector::Z方法的典型用法代码示例。如果您正苦于以下问题:C++ TVector::Z方法的具体用法?C++ TVector::Z怎么用?C++ TVector::Z使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类TVector
的用法示例。
在下文中一共展示了TVector::Z方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: changeDirection
void AutoTank::changeDirection(TVector targetPosition)
{
TVector newDirection = targetPosition - currentPosition;
if(newDirection.X() == 0.0)
angleWithX = 90.0;
else
angleWithX = atan(-newDirection.Z()/newDirection.X()) * 180.0/M_PI;
if(angleWithX < 0.0)
angleWithX += 180.0;
if(newDirection.Z() >0)
angleWithX += 180.0;
collisionBox.updateCollisionBoxAngle(angleWithX);
}
示例2: myInit
void myInit()
{
glActiveTexture(GL_TEXTURE0);
//make the background look like the sky
float blue[4] = {0.5,0.5,1.0,0.0};
glClearColor(0.5, 0.5, 1.0, 0.0);
glShadeModel(GL_SMOOTH);
glEnable(GL_FOG);
glFogfv(GL_FOG_COLOR,blue);
glFogf(GL_FOG_MODE, GL_EXP2);
glFogf(GL_FOG_START, 200);
glFogf(GL_FOG_END, 1000);
glFogf(GL_FOG_DENSITY, gFogDensity);
//initial terrain
myTerrain.initializeTerrain("../Data/Texture/Terrain/sand.tga", "../Data/Texture/Terrain/cactus.tga");
//initial ground collision square
groundCollSquare.setParameters(TVector(0.0, 1.0, 0.0), gCenterPoint);
//initial tank
tankHeightPos = myTerrain.GetHeight(gCenterPoint.X()+100.0, gCenterPoint.Z());
myTank.setParameters("T-90.3DS", "../T-90/",TVector(gCenterPoint.X()-600.0, tankHeightPos + 9.0, gCenterPoint.Z()-20), 0.0, &myTerrain, &collisionBoxArray, &wall);
myTank.initTank();
unsigned int brickTexture;
createTexture("../Data/Texture/Brick/brick.bmp", brickTexture);
wall.Init(myTank.getPosition().X() + 50, myTank.getPosition().Y()-8, myTank.getPosition().Z() + 20, NUM_BRICKS, brickTexture, &myTerrain);
}
示例3: DrawGLScene
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
int i;
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//set camera in hookmode
/*if (hook_toball1)
{
TVector unit_followvector=ArrayVel[0];
unit_followvector.unit();
gluLookAt(ArrayPos[0].X()+250,ArrayPos[0].Y()+250 ,ArrayPos[0].Z(), ArrayPos[0].X()+ArrayVel[0].X() ,ArrayPos[0].Y()+ArrayVel[0].Y() ,ArrayPos[0].Z()+ArrayVel[0].Z() ,0,1,0);
}
else*/
gluLookAt(pos.X(),pos.Y(),pos.Z(), pos.X()+dir.X(),pos.Y()+dir.Y(),pos.Z()+dir.Z(), 0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
//glRotatef(camera_rotation,0,1,0);
//render balls
for (i=0;i<NrOfBalls;i++)
{
switch(i){
case 1: glColor3f(1.0f,1.0f,1.0f);
break;
case 2: glColor3f(1.0f,1.0f,0.0f);
break;
case 3: glColor3f(0.0f,1.0f,1.0f);
break;
case 4: glColor3f(0.0f,1.0f,0.0f);
break;
case 5: glColor3f(0.0f,0.0f,1.0f);
break;
case 6: glColor3f(0.65f,0.2f,0.3f);
break;
case 7: glColor3f(1.0f,0.0f,1.0f);
break;
case 8: glColor3f(0.0f,0.7f,0.4f);
break;
default: glColor3f(1.0f,0,0);
}
glPushMatrix();
glTranslated(ArrayPos[i].X(),ArrayPos[i].Y(),ArrayPos[i].Z());
gluSphere(cylinder_obj,20,20,20);
glPopMatrix();
}
glEnable(GL_TEXTURE_2D);
//render walls(planes) with texture
glBindTexture(GL_TEXTURE_2D, texture[3]);
glColor3f(1, 1, 1);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(320,320,320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(320,-320,320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-320,-320,320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-320,320,320);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-320,320,-320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-320,-320,-320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(320,-320,-320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(320,320,-320);
glTexCoord2f(1.0f, 0.0f); glVertex3f(320,320,-320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(320,-320,-320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(320,-320,320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(320,320,320);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-320,320,320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(-320,-320,320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(-320,-320,-320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-320,320,-320);
glEnd();
//render floor (plane) with colours
glBindTexture(GL_TEXTURE_2D, texture[2]);
glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f); glVertex3f(-320,-320,320);
glTexCoord2f(1.0f, 1.0f); glVertex3f(320,-320,320);
glTexCoord2f(0.0f, 1.0f); glVertex3f(320,-320,-320);
glTexCoord2f(0.0f, 0.0f); glVertex3f(-320,-320,-320);
glEnd();
//render columns(cylinders)
glBindTexture(GL_TEXTURE_2D, texture[0]); /* choose the texture to use.*/
glColor3f(0.5,0.5,0.5);
glPushMatrix();
glRotatef(90, 1,0,0);
glTranslatef(0,0,-500);
gluCylinder(cylinder_obj, 60, 60, 1000, 20, 2);
glPopMatrix();
/*glPushMatrix();
glTranslatef(200,-300,-500);
gluCylinder(cylinder_obj, 60, 60, 1000, 20, 2);
//.........这里部分代码省略.........
示例4: DrawLoadScreen
//===========================================================
// BOOL DrawLoadScreen ()
//===========================================================
BOOL DrawLoadScreen () {
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(pos.X(),pos.Y(),pos.Z(), pos.X()+dir.X(),pos.Y()+dir.Y(),pos.Z()+dir.Z(), 0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glColor3f (1.0f, 0.0f, 1.0f);
glPushMatrix();
glTranslated(ball.position.X(),ball.position.Y(),ball.position.Z());
gluSphere(cylinder_obj,BALL_RADIUS,20,20);
glPopMatrix();
glPushMatrix();
glLoadIdentity();
glTranslatef(-180,0,0);
freetype::print(font, 320, 170, "Load Arkanoid game...\nPress space to continue...");
glPopMatrix();
glPushMatrix();
glLoadIdentity();
glColor3ub(0,0,0xff);
freetype::print(font1, 160, 120, "\nGame control\nplatform: to the left[key_left], right[key_right];\nball: slower[f2], acceleration [f3]\nfullscreen / window mode [f11]");
//glTranslatef(-180,0,0);
glPopMatrix();
glPushMatrix();
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3d(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,paddle.position.Z());
glVertex3d(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,paddle.position.Z());
glVertex3d(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,paddle.position.Z());
glVertex3d(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,paddle.position.Z());
glEnd();
glPopMatrix();
for (int i = 0; i < TARGET_ROW_COUNT; i++)
{
for (int j = 0; j < TARGET_COLUMN_COUNT; j++)
{
if (target[i][j].active)
{
glBindTexture(GL_TEXTURE_2D, texture[i%4]);
glPushMatrix();
glTranslated(target[i][j].position.X(),target[i][j].position.Y(),target[i][j].position.Z());
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1*TARGET_LENGTH/2, -1*TARGET_HEIGHT/2, 0);
glTexCoord2f(1.0f,0.0f); glVertex3f(TARGET_LENGTH/2, -1*TARGET_HEIGHT/2, 0);
glTexCoord2f(1.0f,1.0f); glVertex3f(TARGET_LENGTH/2, TARGET_HEIGHT/2, 0);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1*TARGET_LENGTH/2, TARGET_HEIGHT/2, 0);
glEnd();
glPopMatrix();
}
}
}
keys[VK_RIGHT] = FALSE; keys[VK_LEFT] = FALSE;
glDepthMask(GL_TRUE);
glDisable(GL_BLEND);
return TRUE;
}
示例5: DrawGLScene
//===========================================================
// DrawGLScene()
//===========================================================
BOOL DrawGLScene(GLvoid)
{
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(pos.X(),pos.Y(),pos.Z(), pos.X()+dir.X(),pos.Y()+dir.Y(),pos.Z()+dir.Z(), 0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
if (flag == 1) {
glPushMatrix();
glLoadIdentity();
glTranslatef(-180,0,0);
freetype::print(font, 320, 170, "Winner!!! Score: %d",int(score/cor));
glPopMatrix();
pause = true;
glPushMatrix();
glLoadIdentity();
glColor3ub(0,0,0xff);
freetype::print(font, 160, 120, "\nNew game? [y/n]");
//glTranslatef(-180,0,0);
glPopMatrix();
gof = true;
}
if (flag == 0) pause = false;
//render balls
glColor3f(1.0f,0.0f,1.0f);
glPushMatrix();
glTranslated(ball.position.X(),ball.position.Y(),ball.position.Z());
gluSphere(cylinder_obj,BALL_RADIUS,20,20);
glPopMatrix();
glPushMatrix();
glColor3f(1.0f,1.0f,1.0f);
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glVertex3d(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,paddle.position.Z());
glVertex3d(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()-PADDLE_HEIGHT,paddle.position.Z());
glVertex3d(paddle.position.X()+PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,paddle.position.Z());
glVertex3d(paddle.position.X()-PADDLE_LENGTH,paddle.position.Y()+PADDLE_HEIGHT,paddle.position.Z());
glEnd();
glPopMatrix();
glEnable(GL_TEXTURE_2D);
for (int i = 0; i < TARGET_ROW_COUNT; i++)
{
for (int j = 0; j < TARGET_COLUMN_COUNT; j++)
{
if (target[i][j].active)
{
glBindTexture(GL_TEXTURE_2D, texture[i%4]);
glPushMatrix();
glTranslated(target[i][j].position.X(),target[i][j].position.Y(),target[i][j].position.Z());
glBegin(GL_QUADS);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(0.0f,0.0f); glVertex3f(-1*TARGET_LENGTH/2, -1*TARGET_HEIGHT/2, 0);
glTexCoord2f(1.0f,0.0f); glVertex3f(TARGET_LENGTH/2, -1*TARGET_HEIGHT/2, 0);
glTexCoord2f(1.0f,1.0f); glVertex3f(TARGET_LENGTH/2, TARGET_HEIGHT/2, 0);
glTexCoord2f(0.0f,1.0f); glVertex3f(-1*TARGET_LENGTH/2, TARGET_HEIGHT/2, 0);
glEnd();
glPopMatrix();
}
}
}
glEnable(GL_BLEND);
glDepthMask(GL_FALSE);
glBindTexture(GL_TEXTURE_2D, texture[4]);
for(int i = 0; i < 20; i++)
{
if(ExplosionArray[i].alpha>=0)
{
glPushMatrix();
score += 0.5;
ExplosionArray[i].alpha-=0.01f;
ExplosionArray[i].scale+=0.03f;
glColor4f(1,1,0,ExplosionArray[i].alpha);
glScalef(ExplosionArray[i].scale,ExplosionArray[i].scale,ExplosionArray[i].scale);
glTranslatef((float)ExplosionArray[i].position.X()/ExplosionArray[i].scale, (float)ExplosionArray[i].position.Y()/ExplosionArray[i].scale, (float)ExplosionArray[i].position.Z()/ExplosionArray[i].scale);
glCallList(dlist);
glPopMatrix();
}
}
if ( (!target[0][0].active) && (!target[0][1].active) && (!target[0][2].active) && (!target[0][3].active)&&
//.........这里部分代码省略.........
示例6: moveTo
void AutoTank::moveTo(TVector newPosition)
{
setPosition(newPosition.X(), newPosition.Y(), newPosition.Z());
currentPosition.setY(terrain->GetHeight((float)currentPosition.X(), (float)currentPosition.Z()) + 6.4);
}
示例7: DrawGLScene
int DrawGLScene(GLvoid) // Here's Where We Do All The Drawing
{
int i;
static char frbuf[80] = "";
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//set camera in hookmode
if (hook_toball1)
{
TVector unit_followvector=sphere_speed[0];
unit_followvector.unit();
gluLookAt(sphere_speed[0].X()+250,sphere_speed[0].Y()+250 ,sphere_speed[0].Z(), sphere_speed[0].X()+sphere_speed[0].X() ,sphere_speed[0].Y()+sphere_speed[0].Y() ,sphere_speed[0].Z()+sphere_speed[0].Z() ,0,1,0);
}
else
gluLookAt(pos._x,pos._y,pos._z, pos._x + dir.X(),pos._y+dir.Y(),pos._z+dir.Z(), 0,1.0,0.0);
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glRotatef(camera_rotation,0,1,0);
for (i=0;i<NR_BALLS;i++)
{
switch(i % 7){
case 1: glColor3f(1.0f,1.0f,1.0f);
break;
case 2: glColor3f(1.0f,1.0f,0.0f);
break;
case 3: glColor3f(0.0f,1.0f,1.0f);
break;
case 4: glColor3f(0.0f,1.0f,0.0f);
break;
case 5: glColor3f(0.0f,0.0f,1.0f);
break;
case 6: glColor3f(0.65f,0.2f,0.3f);
break;
case 7: glColor3f(1.0f,0.0f,1.0f);
break;
case 8: glColor3f(0.0f,0.7f,0.4f);
break;
default: glColor3f(1.0f,0,0);
}
glPushMatrix();
glTranslated(sphere_poz[i]._x,sphere_poz[i]._y,sphere_poz[i]._z);
GLUquadricObj *obj = gluNewQuadric();
gluQuadricDrawStyle(obj,GLU_FILL);
gluQuadricNormals(obj,GLU_SMOOTH);
gluQuadricOrientation(obj,GLU_OUTSIDE);
gluSphere(obj, 5.0f, 20, 20);
glPopMatrix();
gluDeleteQuadric(obj);
}
for (i=0;i<NR_CIL;i++)
{
switch(i % 7){
case 1: glColor3f(1.0f,1.0f,1.0f);
break;
case 2: glColor3f(1.0f,1.0f,0.0f);
break;
case 3: glColor3f(0.0f,1.0f,1.0f);
break;
case 4: glColor3f(0.0f,1.0f,0.0f);
break;
case 5: glColor3f(0.0f,0.0f,1.0f);
break;
case 6: glColor3f(0.65f,0.2f,0.3f);
break;
case 7: glColor3f(1.0f,0.0f,1.0f);
break;
case 8: glColor3f(0.0f,0.7f,0.4f);
break;
default: glColor3f(1.0f,0,0);
}
glPushMatrix();
glTranslated(cone_poz[i]._x,cone_poz[i]._y,cone_poz[i]._z);
GLUquadricObj *obj = gluNewQuadric();
gluQuadricDrawStyle(obj,GLU_FILL);
gluQuadricNormals(obj,GLU_SMOOTH);
gluQuadricOrientation(obj,GLU_OUTSIDE);
gluCylinder(obj,5.0, 5.0, 10.0, 20.0, 20.0);
glPopMatrix();
gluDeleteQuadric(obj);
}
float df = 100.0;
for (int i = 0; i < NR_CUBES; i += 1)
{
glPushMatrix();
glTranslated(cube_pos[i]._x,cube_pos[i]._y,cube_pos[i]._z);
glBlendFunc(GL_SRC_ALPHA, GL_ONE);
glDrawCube();
glPopMatrix();
}
//.........这里部分代码省略.........
示例8: caculateCameraView
void caculateCameraView(unsigned int viewMode)
{
switch(viewMode)
{
case 0:
gRadViewAngle = M_PI*angleWithX/180.0 - M_PI;
gCameraPosition.setX(myTank.getPosition().X() + 150*cos(gRadViewAngle));
gCameraPosition.setY(myTank.getPosition().Y() + 30);
gCameraPosition.setZ(myTank.getPosition().Z() - 150*sin(gRadViewAngle));
camera.changePosition(gCameraPosition);
camera.changeTarget(gCameraPosition.X() - 150.0*cos(gRadViewAngle), gCameraPosition.Y(), gCameraPosition.Z() + 150.0*sin(gRadViewAngle));
break;
case 1:
gRadViewAngle = M_PI*myTank.getAngleWithX()/180.0 - M_PI;
gCameraPosition.setX(myTank.getPosition().X() + 250*cos(gRadViewAngle));
gCameraPosition.setY(myTank.getPosition().Y() + 50.0);
gCameraPosition.setZ(myTank.getPosition().Z() - 250*sin(gRadViewAngle));
camera.changePosition(gCameraPosition);
camera.changeTarget(gCameraPosition.X() - 150.0*cos(gRadViewAngle), gCameraPosition.Y(), gCameraPosition.Z() + 150.0*sin(gRadViewAngle));
break;
case 2:
gRadViewAngle = M_PI*myTank.getAngleWithX()/180.0 - M_PI*0.5;
gCameraPosition.setX(myTank.getPosition().X() + 250*cos(gRadViewAngle));
gCameraPosition.setY(myTank.getPosition().Y() + 50.0);
gCameraPosition.setZ(myTank.getPosition().Z() - 250*sin(gRadViewAngle));
camera.changePosition(gCameraPosition);
camera.changeTarget(gCameraPosition.X() - 150.0*cos(gRadViewAngle), gCameraPosition.Y(), gCameraPosition.Z() + 150.0*sin(gRadViewAngle));
break;
case 3:
gRadViewAngle = M_PI*myTank.getAngleWithX()/180.0;
gCameraPosition.setX(myTank.getPosition().X() + 250*cos(gRadViewAngle));
gCameraPosition.setY(myTank.getPosition().Y() + 50.0);
gCameraPosition.setZ(myTank.getPosition().Z() - 250*sin(gRadViewAngle));
camera.changePosition(gCameraPosition);
camera.changeTarget(gCameraPosition.X() - 150.0*cos(gRadViewAngle), gCameraPosition.Y(), gCameraPosition.Z() + 150.0*sin(gRadViewAngle));
break;
}
}
示例9: gCenterPoint
static TVector gCameraPosition;
static TVector gCenterPoint(mapX*mapScale*0.5, 5.0, -mapZ * mapScale*0.5);
static float tankHeightPos;
CollisionSquare groundCollSquare;
CollisionBoxArray collisionBoxArray;
Terrain myTerrain(true, 16);
Tank myTank;
Wall wall;
#define NUM_BRICKS 100
#define SLOWDOWN 0.3
Camera camera(gCenterPoint.X(), 30.0, gCenterPoint.Z(), gCenterPoint.X()+100.0, 10.0, gCenterPoint.Z(),0.0,1.0,0.0);
GLfloat lightPosition[]= {gCenterPoint.X() + 450, 450, gCenterPoint.Z() + 50, 1.0f };
GLint shadowSize = 512;
//prototype funciton
void draw();
void myReshape(int width, int height);
void mySetLight();
void quit();
void caculateCameraView(unsigned int viewMode);
//=======================================
void draw()