📄 car.cpp
字号:
#include <windows.h>
#include <gl/Gl.h>
#include <gl/glut.h>
#include "mobjfile.h"
#include "car.h"
Car::Car(void)
{
MinLengthVertex = MaxLengthVertex = 0;
MinWidthVertex = MaxWidthVertex = 0;
MinHeightVertex = MinHeightVertex = 0;
ScalerFactor = 1;
}
Car::~Car(void)
{
if ( vList ) glDeleteLists(CarList,1);
}
void Car::Draw()
{
if ( vList ) glCallList(CarList);
}
void Car::LoadCarFile(const char *fileName)
{
LoadFile(fileName);
MinLengthVertex = MaxLengthVertex = vList[1].P[0];
MinWidthVertex = MaxWidthVertex = vList[1].P[1];
MinHeightVertex = MaxHeightVertex = vList[1].P[2];
if ( vList )
for(int i = 2 ; i < NumOfVertex + 1 ; i++) {
if ( vList[i].P[0] < MinLengthVertex ) MinLengthVertex = vList[i].P[0];
if ( vList[i].P[0] > MaxLengthVertex ) MaxLengthVertex = vList[i].P[0];
if ( vList[i].P[1] < MinWidthVertex ) MinWidthVertex = vList[i].P[1];
if ( vList[i].P[1] > MaxWidthVertex ) MaxWidthVertex = vList[i].P[1];
if ( vList[i].P[2] < MinHeightVertex ) MinHeightVertex = vList[i].P[2];
if ( vList[i].P[2] > MaxHeightVertex ) MaxHeightVertex = vList[i].P[2];
}
CarList = glGenLists(1);
glNewList(CarList,GL_COMPILE);
glBegin(GL_TRIANGLES);
for(int i = 0 ; i < NumOfFace ; i++)
for(int j = 0 ; j < 3 ; j++) {
glColor4fv(mList[fList[i][j].IndexOfMaterial].Ka);
glNormal3fv(nList[fList[i][2 - j].IndexOfNormal].P);
glVertex3f(vList[fList[i][2 - j].IndexOfVertex].P[0] * ScalerFactor,
vList[fList[i][2 - j].IndexOfVertex].P[1] * ScalerFactor,
vList[fList[i][2 - j].IndexOfVertex].P[2] * ScalerFactor);
}
glEnd();
glEndList();
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -