#include <windows.h>
#include <stdio.h>
#include <gl\gl.h>
#include <gl\glu.h>
#include <gl\glaux.h>
#include <math.h>
#include <time.h>
#include "MilkshapeModel.h" // Header File For Milkshape File
HDC hDC=NULL;
HGLRC hRC=NULL;
HWND hWnd=NULL;
HINSTANCE hInstance;
typedef struct {
int frame;
float xc;
float yc;
float zc;
float anc;
int gira;
int vel;
float Iox;
float Ioy;
float Ioz;
int cameratype;
} VAR;
VAR var; // Global Variables
bool keys[256];
bool active=TRUE;
bool fullscreen=TRUE;
Model *Auto = NULL; // Auto Model
Model *Ruota = NULL; // Wheel Model
GLuint texture[3];
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);
// **********************************************************************VARIABLES
typedef struct
{
double x;
double y;
double z;
} Vector;
typedef struct // Car structure
{
// Car
float x;
float y;
float z;
float any;
float dany;
float velocita;
float vf;
float dvf;
// Ruote
float xruote[4];
float yruote[4];
float zruote[4];
float anruote;
float gira;
} CAR;
CAR car;
typedef struct // Smoke Structure
{
float x;
float y;
float z;
float dx;
float dy;
float dz;
float dim;
float ddim;
} PUF;
#define MAXSMOKE 64
PUF smoke[MAXSMOKE]; // Smoke Array
#define DIMX 64
#define DIMZ 64
#define SIZE 32
Vector Buf[DIMX][DIMZ]; // Terrain
// **********************************************************************MY FUNCTIONS
double VectorLength( Vector v )
{
return sqrt(v.x * v.x + v.y * v.y + v.z * v.z);
}
//-------------------------------------------------------------------
Vector VectorNormalize( Vector v )
{
Vector vresult;
double l = VectorLength( v );
vresult.x = v.x/l;
vresult.y = v.y/l;
vresult.z = v.z/l;
return vresult;
}
//-------------------------------------------------------------------
Vector VectorMultiply( Vector v1, Vector v2 )
{
Vector vresult;
vresult.x = v1.y * v2.z - v1.z * v2.y;
vresult.y = v1.z * v2.x - v1.x * v2.z;
vresult.z = v1.x * v2.y - v1.y * v2.x;
return vresult;
}
//-------------------------------------------------------------------
Vector VectorScalarMultiply( Vector v, double s )
{
Vector vresult;
vresult.x = v.x * s;
vresult.y = v.y * s;
vresult.z = v.z * s;
return vresult;
}
//-------------------------------------------------------------------
Vector VectorDiff( Vector v1, Vector v2 )
{
Vector vresult;
vresult.x = v1.x - v2.x;
vresult.y = v1.y - v2.y;
vresult.z = v1.z - v2.z;
return vresult;
}
void Luce(double x, double y, double z,double dimensione,float r,float g,float b,float iox,float ioy,float ioz,int Tex)
{
Vector Position;
Vector MyPosition;
Position.x = x;
Position.y = y;
Position.z = z;
MyPosition.x=iox;
MyPosition.y=ioy;
MyPosition.z=ioz;
Vector sight = VectorDiff(MyPosition, Position);
Vector cz;
cz.x = 0;
cz.y = 0;
cz.z = 1;
Vector cross1 = VectorMultiply( sight, cz );
Vector cross2 = VectorMultiply( sight, cross1 );
cross1 = VectorNormalize(cross1);
cross2 = VectorNormalize(cross2);
cross1 = VectorScalarMultiply(cross1, dimensione);
cross2 = VectorScalarMultiply(cross2, dimensione);
glColor3f(r,g,b);
glEnable(GL_TEXTURE_2D);
glEnable (GL_BLEND);
glBlendFunc( (1,1,1,1), (1,1,1,1));
glDepthMask (GL_FALSE);
glBindTexture( GL_TEXTURE_2D, texture[Tex] );
glBegin(GL_QUADS);
glTexCoord2d( 0.0, 0.0 );
glVertex3d( Position.x + cross1.x, Position.y + cross1.y, Position.z + cross1.z);
glTexCoord2d( 1.0, 0.0 );
glVertex3d( Position.x - cross2.x, Position.y - cross2.y, Position.z - cross2.z);
glTexCoord2d( 1.0, 1.0 );
glVertex3d( Position.x - cross1.x, Position.y - cross1.y, Position.z - cross1.z);
glTexCoord2d( 0.0, 1.0 );
glVertex3d( Position.x + cross2.x, Position.y + cross2.y, Position.z + cross2.z);
glEnd();
glDisable(GL_TEXTURE_2D);
glDisable (GL_BLEND);
glDepthMask (GL_TRUE);
}
void glPrint(char *ll,float x,float y,float z,float dim,float dir,float r,float g,float b)
{
int t;
char k;
float kx,ky,fx,fy;
fx=(float)1/16;
fy=(float)1/16;
glColor3f(r,g,b);
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, texture[0] );
glEnable (GL_BLEND);
glBlendFunc( (1,1,1,1), (1,1,1,1));
glDepthMask (GL_FALSE);
for(t=0;t<(int)strlen(ll);t++)
{
k=*(ll+t);
if(k>=32)
{
k=k-32;
kx=(float)(k%16);
kx=kx*fx;
ky=15-(float)((int)(k/16));
ky=ky*fy;
glBegin(GL_QUADS);
glTexCoord2d( kx,ky );
glVertex3f(x,y,z);
glTexCoord2d( kx+fx, ky );
glVertex3f(x+dim,y,z);
glTexCoord2d( kx+fx,ky+fy );
glVertex3f(x+dim,y+dim,z);
glTexCoord2d( kx,ky+fy );
glVertex3f(x,y+dim,z);
glEnd();
x=x+dim;
}
}
glDisable(GL_BLEND);
glDepthMask(GL_TRUE);
glDisable(GL_TEXTURE_2D);
}
void InitBuf(void) // Init Terrain
{
int x,z,t;
double xi,zi;
for(z=0;z<DIMZ;z++)
{
zi=(double)z-((double)DIMZ/2);
zi=zi*SIZE;
for(x=0;x<DIMX;x++)
{
xi=(double)x-((double)DIMX/2);
xi=xi*SIZE;
Buf[x][z].x=xi;
if(z==0 || z==DIMZ-2 || x==0 || x==DIMX-2)
Buf[x][z].y=30;
else
Buf[x][z].y=0;
Buf[x][z].z=zi;
}
}
}
void InitSmoke(void) // Init Smoke
{
int t,k=0;
float xf,yf,zf;
for(t=0;t<MAXSMOKE;t++)
{
switch(t%4) // For each Wheel
{
case 0:
xf=2.5;
yf=0.3;
zf=4.5;
break;
case 1:
xf=-2.5;
yf=0.3;
zf=4.5;
break;
case 2:
xf=2.5;
yf=0.3;
zf=-4.5;
break;
case 3:
xf=-2.5;
yf=0.3;
zf=-4.5;
break;
}
smoke[t].x=xf;
smoke[t].y=yf;
smoke[t].z=zf;
smoke[t].dim=0;
smoke[t].ddim=0.5+(float)(rand()%100)/1000;
smoke[t].dx=0;
smoke[t].dy=0.01;
smoke[t].dz=-car.velocita;
}
}
void Init(void)
{
var.frame=0; // Frame rate calculation
// Init Terrain
InitBuf();
// Init the Wheel Smoke
InitSmoke();
// Camera
var.anc=-20;
var.gira=false; // True when the car is steering
var.vel=0; // >0 if the speed car change
var.cameratype=0;
// Car and Wheel Position
car.x=0;
car.y=0.75;
car.z=0;
car.any=0;
car.dany=0;
car.velocita=10; // Initial speed
car.vf=10;
car.dvf=0;
car.xruote[0]=2.4;
car.yruote[0]=0.2;
car.zruote[0]=-5.2;
car.xruote[1]=-2.4;
car.yruote[1]=0.2;
car.zruote[1]=-5.2;
car.xruote[2]=2.4;
car.yruote[2]=0.2;
car.zruote[2]=4.3;
car.xruote[3]=-2.4;
car.yruote[3]=0.2;
car.zruote[3]=4.3;
car.anruote=0; // Wheel Angle
car.gira=0; // Angle for car turning
// Initial Camera Position
var.Iox=car.x+50*cos((car.any+(rand()%90-rand()%90))*3.141/180);
var.Ioy=(float)(1+rand()%10);
var.Ioz=car.z+50*sin((car.any+(rand()%90-rand()%90))*3.141/180);
}
void DrawBuf(void) // Draws the Ground
{
register int x,z,ptr;
register float fk=(float)1/100;
glEnable(GL_TEXTURE_2D);
glBindTexture( GL_TEXTURE_2D, texture[1] );
for(z=0;z<DIMZ-1;z++)
{
for(x=0;x<DIMX-1;x++)
{
glBegin(GL_QUADS);
glTexCoord2d( 0.0, 0.0 );
glVertex3f(Buf[x][z].x,Buf[x][z].y,Buf[x][z].z);
glTexCoord2d( 0.0, 1.0 );
glVertex3f(Buf[x][z+1].x,Buf[x][z+1].y,Buf[x][z+1].z);
glTexCoord2d( 1.0, 1.0 );
glVertex3f(Buf[x+1][z+1].x,Buf[x+1][z+1].y,Buf[x+1][z+1].z);
glTexCoord2d( 1.0, 0.0 );
glVertex3f(Buf[x+1][z].x,Buf[x+1][z].y,Buf[x+1][z].z);
glEnd();
}
}
glDisable(GL_TEXTURE_2D);
}
void DrawSmoke(void) // Draws the Smoke
{
int t;
float xf,yf,zf,kf;
for(t=0;t<MAXSMOKE;t++)
{
kf=1-smoke[t].dim;
glPushMatrix();
glTranslatef(car.x,0,car.z);
glRotatef(car.any,0,1,0);
Luce(smoke[t].x,smoke[t].y,smoke[t].z,smoke[t].dim,kf,kf,kf,var.xc,var.yc,var.zc,2);
glPopMatrix();
smoke[t].dim+=smoke[t].ddim;
if(smoke[t].dim>=1)
{
switch(t%4)
{
case 0:
xf=2.5;
yf=0.3;
zf=4.5;
break;
ca
局外狗
- 粉丝: 83
- 资源: 1万+
最新资源
- 三相逆变器并网,双PI控制
- 双 Richards 方程双渗模型 在裂隙发育完全的边坡,可以使用等效法将裂隙平均到基质中,使用两个里查兹方程来方便描述裂隙的渗流情况和 基质的渗流情况,并考虑裂隙与基质的水交 从数值模拟的结果可
- 该模型在旋转坐标系下采样旋转高频注入的方法进行低速时的无传感器器控制,对静止坐标系下的电流进行同轴系高通滤波器提取负序分量,继而采用外差法进项误差提取,误差代入位置观测器得到PMSM的转子角度
- Matlab基于阈值分割的车牌定位识别 车牌识别主要包括以下三个主要步骤:车牌区域定位、车牌字符分割、车牌字符识别 通过对采集的车牌图像进行灰度变、边缘检测、腐蚀及平滑等过程来进行车牌图像预处理
- 三相PWM整流器simulink仿真模型,采用滑模控制(基于改进变指数趋近率),SVPWM调制策略,可以实现很好的整流直流侧电压超调量仅10V,交流侧谐波含量低于百分之5,且具有很强的鲁棒性
- 法兰克FANUC加工中心三点圆分中宏程序,在工厂使用多年,验证了宏程序的可靠性,此宏程序可以提高对刀速度,提高工作效率
- C#开发的串口通信程序,可适用RS232,485 1,自动检测COM 2,自动发送,自动清空 全部源码开放,适合初学者,也可以截取源码做项目开发 本源程序有需要一定编程能力
- Matlab数字图像处理 压缩包包含.m和.fig文件以及文档,具体实现标准参照以下要求: 第一部分:编写一个基于GUI的图像处理程序 软件,功能按钮和界面布局自己设定,遵循美观大方、方便操作的原则
- 遗传算法代码 旅行商问题(TSP)优化 Matlab代码可用于路径规划,物流配送,路径优化 源码+注释 数据可以修改 多少个坐标都行 帮忙改数据就是另外的价钱旺柴 代码一经出概不 望理解
- 微电网两阶段鲁棒优化程序 基于matlab+yalmip+cplex实现 代码完美地复现了中国电机工程学报的文献《微电网两阶段鲁棒优化经济调度方法-刘一欣》 代码基于matlab+yalmip+cp
- 内容:挖掘源荷两侧低碳资源并分析其低碳性,荷侧调用不同响应速度的价格型、激励型需求响应资源克服多时间尺度下碳捕集电厂综合灵活运行方式的局限,通过源荷资源协调优化,从而提高系统的低碳性能 文献:#计及
- 基于改进多目标粒子群的微电网优化调度模型 提出了一种经济与环保相协调的微电网优化调度模型,针对光伏电池、风机、微型燃气轮机、柴油发电机以及蓄电池组成的微电网系统的优化问题进行研究,在满足系统约束条件下
- 《信号检测与估值理论》Matlab仿真,包括: 高斯-牛顿迭代法对正弦信号参数进行估计、 对阻尼指数信号参数进行估计; 使用Kalman卡尔曼滤波器实现对时变信道估计、飞行器轨迹跟踪; DC电平检测器
- 基于PID的四旋翼无人机轨迹跟踪控制-仿真程序 火 基于MATLAB中Simulink的S-Function模块编写,注释详细,参考资料齐全 2D已有案例: 1 8字形轨迹跟踪
- 51单片机智能加湿器控制系统proteus仿真(仿真+源码+原理图) 仿真图proteus 7.8 protues 8.9 程序编译器:keil 4 keil 5 主要功能: 本设计由STC89C52
- MATLAB手势识别(静态手势识别,视频图像识别)带完整课程设计报告,AD电路图
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈