天空盒陆地行动
来源:互联网 发布:bilibili定时关闭软件 编辑:程序博客网 时间:2024/04/28 12:52
------------西昌.何雨锋 天空盒陆地行动
#include "stdafx.h"
#include "../tv3dcpp.h"
#include
//Setup TrueVision3D
ITVEngine engine1; //引擎
ITVInputEngine input1; //输入引擎
ITVScene scene1; //场景
ITVMesh tea1; //一个实体----茶壶
ITVGlobals global1; //全球变量
ITVAtmosphere atmos1; //环境
void render();
void input();
void unload();
double xrot=0; //
double yrot=0;
double zrot=0;
double xpos=0; //主角位置
double ypos=0;
double zpos=0;
double lookx=0; //主角视点
double looky=0;
double lookz=0;
double xangle=0;
double yangle=0;
double timeleft;
float me_walk = 0.0; //前后移动变量
float me_strafe = 0.0; //左右移动变量
LRESULT CALLBACK WndProc(HWND wpHWnd, UINT msg, WPARAM wParam, LPARAM lParam);
//建立一个窗体
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{
HWND WindowHandle;
// HINSTANCE hInst;
WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, WndProc, 0L, 0L,
GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
"TV3D Tutorial", NULL };
RegisterClassEx(&wc);
WindowHandle = CreateWindow( "TV3D Tutorial", "TV3D Tutorial A01: Basic init",
WS_OVERLAPPEDWINDOW, 100, 100, 640, 480,
GetDesktopWindow(), NULL, wc.hInstance, NULL );
// there is a problem creating the window
if (WindowHandle == NULL)
{
MessageBox(NULL, "Unable to Create a Window", "Error", MB_OK);
return false;
}
ShowWindow (WindowHandle, 1);
UpdateWindow (WindowHandle);
SetFocus (WindowHandle);
ShowCursor (TRUE);
//初始化COM?
CoInitialize(NULL);
engine1 = CreateTVEngine();
//Engine Running boolean
double Gamma = 0.0;
MSG msg;
//将引擎初始化到窗体中
engine1->SetDebugFile("debug.txt");
engine1->Init3DWindowedMode ((long)WindowHandle, true);
//如果要全屏显示把这句改为 engine1->Init3DFullscreen(1024,768,32,true,true,TV_DEPTHBUFFER_BESTBUFFER,1.1,winhand);
//打开显示FPS开关
engine1->put_DisplayFPS(tvtrue);
//将输入引擎、场景、全球变量、环境实例化
input1 = CreateTVInputEngine();
scene1=CreateTVScene();
global1=CreateTVGlobals();
atmos1=CreateTVAtmosphere();
char path[256];
char srchpath[256];
HMODULE Module = (HMODULE)hInstance;
GetModuleFileName(Module,path,255);
AppPath(path,srchpath);
//设置资源文件的路径
engine1->SetSearchDirectory(srchpath);
engine1->SetAngleSystem (TV_ANGLE_DEGREE);
long texture1;
if((texture1=scene1->LoadTexture("..//..//..//media//5.bmp",-1,-1,"t1"))==0)
MessageBox(NULL,"无法读材质","error",0);
scene1->LoadTexture("..//..//..//Media//Sky//Winter//up.jpg",-1,-1,"box_up");
scene1->LoadTexture("..//..//..//Media//Sky//Winter//down.jpg",-1,-1,"box_down");
scene1->LoadTexture("..//..//..//Media//Sky//Winter//left.jpg",-1,-1,"box_left");
scene1->LoadTexture("..//..//..//Media//Sky//Winter//right.jpg",-1,-1,"box_right");
scene1->LoadTexture("..//..//..//Media//Sky//Winter//front.jpg",-1,-1,"box_front");
scene1->LoadTexture("..//..//..//Media//Sky//Winter//back.jpg",-1,-1,"box_back");
//读天空材质并将其取名,然后用atmos的天空盒功能显示六面天空
atmos1->SkyBox_SetTexture(global1->GetTex("box_front"),global1->GetTex("box_back"),global1->GetTex("box_left"),global1->GetTex("box_right"),global1->GetTex("box_up"),global1->GetTex("box_down"));
atmos1->SkyBox_Enable(tvtrue,tvtrue);
//在场景scene1中建立出茶壶
tea1=scene1->CreateMeshBuilder("teapot");
tea1->CreateTeapot();
tea1->EnableSphereMapping(tvtrue,-1,-1);
tea1->SetTexture(global1->GetTex("t1"),-1);
//global全球变量看来可以用来装已经读取并命名的
xrot=1;yrot=1;zrot=1;
xpos=3;ypos=3;zpos=15;
tea1->SetPosition(1,1,15);
tea1->SetRotation(1,1,10);
scene1->SetCamera(xpos,ypos,zpos,xrot,yrot,zrot);//相机位即我位
scene1->SetViewFrustum (60, 10000);
//Main loop
while( msg.message!=WM_QUIT)
{
if(PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
{
TranslateMessage( &msg );
DispatchMessage( &msg );
}
else
{
render();
input();
}
}
//Uninitialize the variables
unload();
//Exit sucessfully
return 0;
}
//渲染
void render()
{
engine1->Clear(false);
atmos1->Atmosphere_Render();
scene1->RenderAllMeshes(tvfalse);
//Clear the screen
engine1->RenderToScreen (); //Render the screen
}
//Input sub
void input()
{
if(input1->IsKeyPressed(TV_KEY_ESCAPE)) //Check if ESCAPE has been pressed.
{
PostQuitMessage(0);
}
if(input1->IsKeyPressed(TV_KEY_W))
me_walk = 1;
if(input1->IsKeyPressed(TV_KEY_S))
me_walk = -1;
if(input1->IsKeyPressed(TV_KEY_A))
me_strafe = 1;
if(input1->IsKeyPressed(TV_KEY_D))
me_strafe = -1;
long mousex = 0; long mousey = 0;
int mouse_b1 = 0; int mouse_b2 = 0; int mouse_b3 = 0;
long mouse_old = 0; long mouse_new = 0;
mouse_old = mouse_new;
input1->GetMouseState(&mousex,&mousey,(short *)&mouse_b1,(short *)&mouse_b2,(short *)&mouse_b3,&mouse_old);
xangle = xangle - ((float)mousey / 100.0f);
yangle = yangle - ((float)mousex / 100.0f);
if(xangle > 1.3f) xangle = 1.3f;
if(xangle < -1.3f) xangle = -1.3f;
if(me_walk > 0)
{
me_walk = me_walk - 0.05f;
if(me_walk < 0) me_walk = 0;
}
if(me_walk < 0)
{
me_walk = me_walk + 0.05f;
if(me_walk > 0) me_walk = 0;
}
if(me_strafe > 0)
{
me_strafe = me_strafe - 0.05f;
if(me_strafe < 0) me_strafe = 0;
}
if(me_strafe < 0)
{
me_strafe = me_strafe + 0.05f;
if(me_strafe > 0) me_strafe = 0;
}
timeleft=engine1->TimeElapsed();
//不知道hl中是否也这样写的呢?上下移动是否与鼠标无关?
xpos = xpos + (cosf(yangle) * me_walk * timeleft) + (cosf(yangle + 3.141596f / 2.0f) * me_strafe * timeleft);
zpos = zpos + (sinf(yangle) * me_walk * timeleft) + (sinf(yangle + 3.141596f / 2.0f) * me_strafe * timeleft);
lookx = xpos + cosf(yangle);
looky = ypos + tanf(xangle);
lookz = zpos + sinf(yangle);
scene1->SetCamera(xpos,ypos,zpos,lookx,looky,lookz);
}
void unload()
{
scene1->DestroyAllMeshes();
scene1->Release();
scene1=NULL;
input1->Release();
input1=NULL;
engine1->Release;
engine1=NULL;
CoUninitialize();
}
LRESULT CALLBACK WndProc(HWND wpHWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
switch(msg)
{
case WM_DESTROY:
{
PostQuitMessage(0);
return 0;
} break;
default:break;
}
return DefWindowProc(wpHWnd, msg, wParam, lParam);
}
------------------------------------
怎么让一幅图片成为整个地图的材质呢,而不是那种平铺
land1->CreateDynTextures(128,128,tvfalse,tvtrue);
land1->SetTexture(global1->GetTex("map1"),1);
land1->SetTextureScale(1,1,1);
land1->DynDrawTexture(global1->GetTex("map1"),5000,5000,1,1,global1->RGBA(170,200,170,0.1),tvtrue,tvfalse,1,1,1,1);
---------------------------------------
在天空盒显示时,设置scene场景的背景将无效
scene1->SetSceneBackGround(0.5,0.1,0.5); //无效果
- 天空盒陆地行动
- 陆地
- 天空盒、天空穹和天空面
- 天空盒
- 天空盒
- 天空盒
- 天空穹,天空面,天空盒的学习
- Ogre 创建天空盒、天空穹、天空面
- OpenGL 天空盒
- 天空盒的制作
- unity3d天空盒
- osg创建天空盒
- DX9实现天空盒
- Unity:天空盒
- unity3d添加天空盒
- Unity3D添加天空盒
- unity3d天空盒
- Unity3D添加天空盒
- 摄象机及工厂
- 启动Oracle常见疑难问题分析(8i)
- 鼠标抓取
- 水
- 特效
- 天空盒陆地行动
- Ubuntu10.04中手动安装最新jdk
- 纹理灯光材质关系
- LINUX学习之初学GCC
- 起雾
- 写文字
- 修改MDL模型
- eclipse 注释规范设置
- 详解ASP.NET页面生命周期