⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mainframe.cpp

📁 最新visualC++编程200例书籍源码包括对数据库的操作
💻 CPP
字号:
/************************************
 * A C++ Glut Wrapper				*
 * Author: Andrea Ingegneri			*
 * Date: 16/12/2001					*
 * Distribution: LGPL (www.gnu.org) *
 ************************************/

#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

#include <glut.h>

#include "c3ds.h"
#include "wndframe.h"
#include "VECTOR.h"
#include "MATRIX.h"
#include "C3DModel.h"

class CAppFrame : public CWindow
{
public:
	CAppFrame(string Name, int PosX, int PosY, int DimX, int DimY);
	void	Display(void);
	void	Reshape(int DimX, int DimY);
	void	Idle(void);
	void	Init(void);
	void	Keyboard(unsigned char key, int x, int y);
// Application frames
	C3DModel	*ModelloPtr;
private:
	float		mScale;
	float		Degree;
};

CAppFrame::CAppFrame(string Name, int PosX, int PosY, int DimX, int DimY) : 
					 CWindow(Name, PosX, PosY, DimX, DimY), Degree(0), mScale(100.0f)
{
	ModelloPtr = new C3DModel();
	ModelloPtr->ProcessFile("0155.3ds");
	cout << "File Loaded" << endl;
	int nobj = ModelloPtr->GetObjNumber();

	for (int i = 0; i < nobj; i++)
	{
		C3DObject *ObjectPtr;
		ObjectPtr = ModelloPtr->GetObject(i);
		ObjectPtr->UseTrasform();
	}

}

void CAppFrame::Reshape(int DimX, int DimY)
{
	if (DimY==0)        // Prevent A Divide By Zero By
	{
		DimY=1;        // Making Height Equal One
	}

	glViewport(0, 0, DimX, DimY);   // Reset The Current Viewport
	glMatrixMode(GL_PROJECTION);    // Select The Projection Matrix
	glLoadIdentity();       // Reset The Projection Matrix

	// Calculate The Aspect Ratio Of The Window
	gluPerspective(45.0f,(GLfloat)DimX/(GLfloat)DimY,0.1f,100.0f);

	glMatrixMode(GL_MODELVIEW);     // Select The Modelview Matrix
	glLoadIdentity();       // Reset The Modelview Matrix
}

void CAppFrame::Display()
{
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
	glLoadIdentity();         // Reset The Current Modelview Matrix
	glTranslatef(0.0f,0.0f,-6.0f);      // Move Left 1.5 Units And Into The Screen 6.0

	glRotatef(Degree, 1, 1, 2);

	int nobj = ModelloPtr->GetObjNumber();

	for (int i = 0; i < nobj; i++)
	{
		C3DObject *ObjectPtr;
		ObjectPtr = ModelloPtr->GetObject(i);
		int nfaces = ObjectPtr->faces.size();
		for(int face = 0; face < nfaces; face++)
		{
			C3DFace *FacePtr;
			FacePtr = &ObjectPtr->faces[face];
			int A, B, C;
			A = FacePtr->A;
			B = FacePtr->B;
			C = FacePtr->C;
			glBegin(GL_LINES);        // Drawing Using Triangles
				glVertex3f( ObjectPtr->vertices[A].x/mScale, ObjectPtr->vertices[A].y/mScale, ObjectPtr->vertices[A].z/mScale);     // Top
				glVertex3f( ObjectPtr->vertices[B].x/mScale, ObjectPtr->vertices[B].y/mScale, ObjectPtr->vertices[B].z/mScale);     // Top
			glEnd();           // Finished Drawing The Triangle
			glBegin(GL_LINES);        // Drawing Using Triangles
				glVertex3f( ObjectPtr->vertices[B].x/mScale, ObjectPtr->vertices[B].y/mScale, ObjectPtr->vertices[B].z/mScale);     // Top
				glVertex3f( ObjectPtr->vertices[C].x/mScale, ObjectPtr->vertices[C].y/mScale, ObjectPtr->vertices[C].z/mScale);     // Top
			glEnd();           // Finished Drawing The Triangle
			glBegin(GL_LINES);        // Drawing Using Triangles
				glVertex3f( ObjectPtr->vertices[C].x/mScale, ObjectPtr->vertices[C].y/mScale, ObjectPtr->vertices[C].z/mScale);     // Top
				glVertex3f( ObjectPtr->vertices[A].x/mScale, ObjectPtr->vertices[A].y/mScale, ObjectPtr->vertices[A].z/mScale);     // Top
			glEnd();           // Finished Drawing The Triangle
		}
	}

//	glFlush();
	glutSwapBuffers();
}

void CAppFrame::Idle()
{
	Degree += 0.25f;
	if (Degree >= 360)
		Degree = 0;
	Display();
}

void CAppFrame::Init()
{
	glShadeModel(GL_SMOOTH);       // Enable Smooth Shading
	glClearColor(0.0f, 0.0f, 0.0f, 0.5f);    // Black Background
	glClearDepth(1.0f);         // Depth Buffer Setup
	glEnable(GL_DEPTH_TEST);       // Enables Depth Testing
	glDepthFunc(GL_LEQUAL);        // The Type Of Depth Testing To Do
	glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST); // Really Nice Perspective Calculations
}

void CAppFrame::Keyboard(unsigned char key, int x, int y)
{
	if (key == '-')
		mScale -= 1.0f;
	if (key == '+')
		mScale += 1.0f;
}

void main()
{
	CViewControl Control("Ciao");
//	CWindow	Finestra1("Hello World", 10, 10, 400, 400);
	CAppFrame Finestra2("Hello", 10, 10, 400, 400);
	Control.AppendWindow(&Finestra2);
	Control.Start();
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -