📄 main.cpp
字号:
if( currentTime - previousTime > 1.0f )
{
previousTime = currentTime;
//sprintf(strFPS, "FPS: %d", int(fps));
return int(fps);
//fps1=fps;
//strFPS[1]=0;
//SetWindowText(g_hWnd, strFPS);
// fps = 0.0f;
}
//else
// return(fps1);
}
int m=-1;
void makeobject(t3DModel &g_3DModel,int no)
{
for(int i = 0; i < g_3DModel.numOfObjects; i++)
{
// Make sure we have valid objects just in case. (size() is in the vector class)
if(g_3DModel.pObject.size() <= 0) break;
// Get the current object that we are displaying
t3DObject *pObject = &g_3DModel.pObject[i];
if(i!=4)
{
glBindTexture(GL_TEXTURE_2D, texture[19]);
// glEnable(GL_TEXTURE_2D);
}
if(i==4)
glBindTexture(GL_TEXTURE_2D, texture[20]);
else
{
// glEnable(GL_TEXTURE_2D);
}
/*if(i==2)
glBindTexture(GL_TEXTURE_2D, texture[19]);
if(i==3)
glBindTexture(GL_TEXTURE_2D, texture[19]);
if(i==4)
glBindTexture(GL_TEXTURE_2D, texture[19]);*/
// Check to see if this object has a texture map, if so bind the texture to it.
/* if(pObject->bHasTexture) {
// Turn on texture mapping and turn off color
glEnable(GL_TEXTURE_2D);
// Reset the color to normal again
glColor3ub(255, 255, 255);
// Bind the texture map to the object by it's materialID
glBindTexture(GL_TEXTURE_2D, g_Texture[pObject->materialID]);
} else {
// Turn off texture mapping and turn on color
glDisable(GL_TEXTURE_2D);
// Reset the color to normal again
glColor3ub(255, 255, 255);
}*/
// This determines if we are in wireframe or normal mode
//glTranslated(0,0,0);
/*if(no==1)
{
//if(m==1)
//{
if (deltaAngle) {
if(deltaAngle==-1)
angle+=0.025;
if(deltaAngle==1)
angle-=0.025;
glTranslated(st.position.x,0,st.position.z);
glRotated(10,0,1,0);
glTranslated(-st.position.x,0,-st.position.z);
}
}*/
/*}
else
if(m==0)
{
glTranslated(st.position.x,0,st.position.z);
glRotated(ang,0,1,0);
glTranslated(-st.position.x,0,-st.position.z);
}
}*/
glBegin(g_ViewMode); // Begin drawing with our selected mode (triangles or lines)
// Go through all of the faces (polygons) of the object and draw them
for(int j = 0; j < pObject->numOfFaces; j++)
{
// Go through each corner of the triangle and draw it.
//glBindTexture(GL_TEXTURE_2D, texture[19]);
//glBegin(GL_TRIANGLE)
for(int whichVertex = 0; whichVertex < 3; whichVertex++)
{
// Get the vertex index for each point of the face
int vertIndex = pObject->pFaces[j].vertIndex[whichVertex];
// Give OpenGL the normal for this vertex.
glNormal3f(pObject->pNormals[ vertIndex ].x, pObject->pNormals[ vertIndex ].y, pObject->pNormals[ vertIndex ].z);
// If the object has a texture associated with it, give it a texture coordinate.
if(pObject->bHasTexture) {
// Make sure there was a UVW map applied to the object or else it won't have tex coords.
if(pObject->pTexVerts) {
// Get the texture coordinate index
int coordIndex = pObject->pFaces[j].coordIndex[whichVertex];
// Assign the UV coordinates to the current vertex being rendered
glTexCoord2f(pObject->pTexVerts[ coordIndex ].x, pObject->pTexVerts[ coordIndex ].y);
}
} else {
// Make sure there is a valid material/color assigned to this object.
// You should always at least assign a material color to an object,
// but just in case we want to check the size of the material list.
// if the size is at least one, and the material ID != -1,
// then we have a valid material.
if(g_3DModel.pMaterials.size() && pObject->materialID >= 0)
{
// Get and set the color that the object is, since it must not have a texture
float *pColor = g_3DModel.pMaterials[pObject->materialID].fColor;
// Assign the current color to this model
glColor3f(pColor[0], pColor[1], pColor[2]);
}
}
if(tex ==1)
glTexCoord2f(0.0f, 0.0f); tex++;
if(tex == 2)
glTexCoord2f(1.0f, 0.0f); tex++;
if(tex == 3)
glTexCoord2f(0.0f, 1.0f); tex = 1;
// P ass inthe current vertex of the object (Corner of current face)
if(no==1)
glVertex3f(pObject->pVerts[ vertIndex ].x+st.position.x, pObject->pVerts[ vertIndex ].y, pObject->pVerts[ vertIndex ].z+st.position.z);
else
glVertex3f(pObject->pVerts[ vertIndex ].x, pObject->pVerts[ vertIndex ].y, pObject->pVerts[ vertIndex ].z);
}
}
glEnd();
// End the drawing
/*if(no==1)
{
/* if(m==1)
{
glTranslated(st.position.x,0,st.position.z);
glRotated(0.125,0,1,0);
glTranslated(-st.position.x,0,-st.position.z);
} */
//m=-1;
/*}
else
if(m==0)
{
glTranslated(st.position.x,0,st.position.z);
glRotated(-ang,0,1,0);
glTranslated(-st.position.x,0,-st.position.z);
m=-1;
}
}*/
}
}
/*int Collision_BoundingBox(int maxbox, tVector3 point)
{
for (int i = 0; i < maxbox; i++)
{
if (Inside_BoundingBox(i,point) == 1) return i;
}
return -1;
}*/
struct bbox
{
cvector max;
cvector min;
};
bbox* Calculate_BoundingBox(t3DModel &m3DModel)
{
bbox bbArray[10];
for(int i = 0; i < m3DModel.numOfObjects; i++)
{
bbArray[i].min.x = 999999.9f;
bbArray[i].max.x = -999999.9f;
bbArray[i].min.z = 999999.9f;
bbArray[i].max.z = -999999.9f;
}
for(int i = 0; i < m3DModel.numOfObjects; i++)
{
t3DObject *pObject = &m3DModel.pObject[i];
for(int j = 0; j < pObject->numOfFaces; j++)
{
for(int whichVertex = 0; whichVertex < 3; whichVertex++)
{
int index = pObject->pFaces[j].vertIndex[whichVertex];
// init bounding box min/max values
if (bbArray[i].min.x == 0) bbArray[i].min.x = 999999.9f;
if (bbArray[i].max.x == 0) bbArray[i].max.x = -999999.9f;
if (bbArray[i].min.z == 0) bbArray[i].min.z = 999999.9f;
if (bbArray[i].max.z == 0) bbArray[i].max.z = -999999.9f;
// if (bbArray[i].min.y == 0) bbArray[i].min.y = 999999.9f;
// if (bbArray[i].max.y == 0) bbArray[i].max.y = -999999.9f;
// calculate bounding box min/max values
if (pObject->pVerts[index].x < bbArray[i].min.x ) bbArray[i].min.x = pObject->pVerts[index].x ;
if (pObject->pVerts[index].x > bbArray[i].max.x ) bbArray[i].max.x = pObject->pVerts[index].x ;
// if (pObject->pVerts[index].y < bbArray[i].min.y ) bbArray[i].min.y = pObject->pVerts[index].y ;
// if (pObject->pVerts[index].y > bbArray[i].max.y ) bbArray[i].max.y = pObject->pVerts[index].y ;
if (pObject->pVerts[index].z < bbArray[i].min.z ) bbArray[i].min.z = pObject->pVerts[index].z ;
if (pObject->pVerts[index].z > bbArray[i].max.z ) bbArray[i].max.z = pObject->pVerts[index].z ;
}
}
}
return bbArray;
}
bool Inside_BoundingBox(float x, float z)
{
if( maxx < x )
return false;
if( minx > x )
return false;
if( maxz < z )
return false;
if( minz > z )
return false;
return true;
}
void drawskybox(float x, float y, float z, float width ,float height, float length)
{
//Drawing the SKY
// Bind the BACK texture of the sky map to the BACK side of the cube
glBindTexture(GL_TEXTURE_2D, texture[1]);
// clamp texture to edge
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// This centers the sky box around (x, y, z)
x = x - width / 2;
y = y - height / 2;
z = z - length / 2;
// Start drawing the side as a QUAD
glBegin(GL_QUADS);
// Assign the texture coordinates and vertices for the BACK Side
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + width, y, z);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + width, y + height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + height, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z);
glEnd();
// Bind the FRONT texture of the sky map to the FRONT side of the box
glBindTexture(GL_TEXTURE_2D, texture[1]);
// clamp texture to edge
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Start drawing the side as a QUAD
glBegin(GL_QUADS);
// Assign the texture coordinates and vertices for the FRONT Side
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z + length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y + height, z + length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y + height, z + length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y, z + length);
glEnd();
// Bind the TOP texture of the sky map to the TOP side of the box
glBindTexture(GL_TEXTURE_2D, texture[1]);
// clamp texture to edge
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Start drawing the side as a QUAD
glBegin(GL_QUADS);
// Assign the texture coordinates and vertices for the TOP Side
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y + height, z);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y + height, z + length);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y + height, z + length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y + height, z);
glEnd();
// Bind the LEFT texture of the sky map to the LEFT side of the box
glBindTexture(GL_TEXTURE_2D, texture[1]);
// clamp texture to edge
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Start drawing the side as a QUAD
glBegin(GL_QUADS);
// Assign the texture coordinates and vertices for the LEFT Side
glTexCoord2f(1.0f, 1.0f); glVertex3f(x, y + height, z);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x, y + height, z + length);
glTexCoord2f(0.0f, 0.0f); glVertex3f(x, y, z + length);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x, y, z);
glEnd();
// Bind the RIGHT texture of the sky map to the RIGHT side of the box
glBindTexture(GL_TEXTURE_2D, texture[1]);
// clamp texture to edge
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// Start drawing the side as a QUAD
glBegin(GL_QUADS);
// Assign the texture coordinates and vertices for the RIGHT Side
glTexCoord2f(0.0f, 0.0f); glVertex3f(x + width, y, z);
glTexCoord2f(1.0f, 0.0f); glVertex3f(x + width, y, z + length);
glTexCoord2f(1.0f, 1.0f); glVertex3f(x + width, y + height, z + length);
glTexCoord2f(0.0f, 1.0f); glVertex3f(x + width, y + height, z);
glEnd();
}
int o=1;
bbox car;
int tex3=1;//int frame =0;
void Renderstart()
{
gluLookAt(0,0,0 ,0,20,-100, 0, 1, 0);
while(tex3!=20)
{
glBindTexture(GL_TEXTURE_2D, texture[26]);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -