Code: Select all
#include "Main_Game.h"
#include "VD.h"
#include <Cg/Cg.h>
#include <IrrCg.h>
#pragma comment(lib,"IrrCg.lib")
#pragma comment(lib,"cg.lib")
#pragma comment(lib,"cgD3D9.lib")
#pragma comment(lib,"cgGL.lib")
using namespace IrrCg;
IrrCg::ICgProgrammingServices* GPU;
//IrrCg::ICgMaterialConstantSetCallBack* MCB;
class MyShaderConstants : public ::IrrCg::ICgMaterialConstantSetCallBack
{
public:
CGparameter View;
irr::IrrlichtDevice* Device;
virtual void OnSetConstants(IrrCg::ICgD3DServices* services,CGprogram Vertex,CGprogram Pixel,SMaterial Material)
{
View = cgGetNamedParameter(Vertex,"View");
irr::core::matrix4 Matrix;
Matrix = Device->getVideoDriver()->getTransform(E_TRANSFORMATION_STATE::ETS_PROJECTION);
Matrix *= Device->getVideoDriver()->getTransform(E_TRANSFORMATION_STATE::ETS_VIEW);
Matrix *= Device->getVideoDriver()->getTransform(E_TRANSFORMATION_STATE::ETS_WORLD);
services->setMatrix(View,IrrCg::MATRIX_IDENTITY,Matrix);
}
};
int Main_Game::PreludeLevel()
{
if(this->Device)
{
Input_Receiver = new MyEventReceiver();
Device->setEventReceiver(this->Input_Receiver);
GPU = new IrrCg::ICgProgrammingServices(this->Device);
if(GPU)
{
//GUI->addMessageBox(L"Shaders are working",L"Yay for shaders!",true,EMBF_OK);
}
}
if(!HavokInit.Initialize_Havok())
{
return 1;
}
this->LoadLevel();
this->LoadPlayerMesh();
if(VideoDriver->getDriverType() == E_DRIVER_TYPE::EDT_DIRECT3D9)
{
this->D3DDevice = VideoDriver->getExposedVideoData().D3D9.D3DDev9;
}
ID3DXBuffer* ShaderError;
if(FAILED(D3DXCreateEffectFromFileA(this->D3DDevice,"Shaders//Shader.fx",NULL,NULL,NULL,NULL,&this->Red,&ShaderError)))
{
FILE* File = fopen("Shader.fx","rb");
if(!File)
{
MessageBoxA(NULL,"Shader Not loaded","",MB_OK);
}
}
Red->FindNextValidTechnique(NULL,&this->Technique);
FPS = SceneManager->addCameraSceneNodeFPS(NULL,100,500);
this->Player_Parent = SceneManager->addCubeSceneNode(2,NULL,NULL);
/*
if(FPS)
{
if(Player_Parent)
{
Player_Parent->setMaterialFlag(E_MATERIAL_FLAG::EMF_LIGHTING,false);
Player_Parent->setPosition(vector3df(0,40,0));
Player_Mesh_Node->setPosition(vector3df(0,-40,0));
Player_Mesh_Node->setParent(Player_Parent);
}
}*/
vector3df PlayerVelocity = Player_Parent->getPosition();
vector3df Player_Pos = Player_Parent->getAbsolutePosition();
Player_Pos.Y = 65;
Player_Pos.Z = 10;
while(Device->run())
{
//FPS->setPosition(Player_Pos);
if(Device->isWindowActive())
{
VideoDriver->beginScene(true,true,SColor(255,0,0,0));
D3DXMATRIX View;
D3DXMATRIX Proj;
D3DXVECTOR3 pEye(0,100,-100);
D3DXVECTOR3 pAt(0,100,0);
D3DXVECTOR3 Up(0,1.0,0);
D3DXMATRIX World;
D3DXMatrixLookAtLH(&View,&pEye,&pAt,&Up);
//Render->GetDirect3DDevice9()->SetTransform(D3DTS_VIEW,&View);
Red->SetMatrix("View",&View);
D3DXMatrixPerspectiveFovLH(&Proj,45,1.333,1.0,10000.0);
Red->SetMatrix("Projection",&Proj);
//Render->GetDirect3DDevice9()->SetTransform(D3DTS_PROJECTION,&Proj);
D3DXMatrixTranslation(&World,0,0,0);
Red->SetMatrix("World",&World);
Red->CommitChanges();
Red->Begin(0,0);
Red->BeginPass(0);
Player_Mesh_Node->render();
Red->EndPass();
Red->End();
SceneManager->drawAll();
GUI->drawAll();
VideoDriver->endScene();
}
}
return 1;
}
int Main_Game::LoadLevel()
{
this->Level_Mesh = SceneManager->getMesh("Huge_Level//Level.x");
if(Level_Mesh)
{
Level_Mesh_Node = SceneManager->addAnimatedMeshSceneNode(Level_Mesh);
if(Level_Mesh_Node)
{
Level_Mesh_Node->setMaterialFlag(E_MATERIAL_FLAG::EMF_LIGHTING,false);
}
}
return 1;
}
int Main_Game::LoadPlayerMesh()
{
Player_Mesh = (ISkinnedMesh*)SceneManager->getMesh("Player//Alyx.x");
if(Player_Mesh)
{
Player_Mesh_Node = SceneManager->addAnimatedMeshSceneNode(Player_Mesh);
if(Player_Mesh_Node)
{
Player_Mesh_Node->setMaterialFlag(E_MATERIAL_FLAG::EMF_LIGHTING,false);
}
}
return 1;
}
Oh Also it seems that it gets clipped when you turn the camera and look at another mesh, not sure it it's Irrlicht or the way The FPS camera is made or something.