generated from sigonasr2/CPlusPlusProjectTemplate
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
77 lines
1.5 KiB
77 lines
1.5 KiB
#include "pixelGameEngine.h"
|
|
#define OLC_PGEX_GRAPHICS3D
|
|
#include "olcPGEX_Graphics3D.h"
|
|
|
|
using namespace olc;
|
|
|
|
class Graphics3DPGEX_Example : public olc::PixelGameEngine
|
|
{
|
|
GFX3D::mesh cube;
|
|
GFX3D::PipeLine renderer;
|
|
|
|
GFX3D::vec3d vUp = {0,1,0};
|
|
GFX3D::vec3d vEye = {0,0,-4};
|
|
GFX3D::vec3d vLookDir = {0,0,1};
|
|
|
|
float fTheta=0;
|
|
|
|
Sprite*cubeTex;
|
|
|
|
public:
|
|
Graphics3DPGEX_Example()
|
|
{
|
|
sAppName = "Graphics3D PGEX Example";
|
|
}
|
|
|
|
public:
|
|
bool OnUserCreate() override
|
|
{
|
|
cube.LoadOBJFile("assets/unitcube.obj");
|
|
olc::GFX3D::ConfigureDisplay();
|
|
|
|
cubeTex=new Sprite("assets/dirtblock.png");
|
|
|
|
|
|
renderer.SetProjection(90.0f, (float)ScreenHeight()/(float)ScreenWidth(), 0.1f, 1000.0f, 0.0f, 0.0f, ScreenWidth(), ScreenHeight());
|
|
return true;
|
|
}
|
|
|
|
bool OnUserUpdate(float fElapsedTime) override
|
|
{
|
|
fTheta+=fElapsedTime;
|
|
|
|
Clear(VERY_DARK_BLUE);
|
|
|
|
GFX3D::ClearDepth();
|
|
|
|
GFX3D::vec3d vLookTarget = GFX3D::Math::Vec_Add(vEye, vLookDir);
|
|
|
|
renderer.SetCamera(vEye, vLookTarget, vUp);
|
|
|
|
GFX3D::mat4x4 matRotateX=GFX3D::Math::Mat_MakeRotationX(fTheta);
|
|
GFX3D::mat4x4 matRotateZ=GFX3D::Math::Mat_MakeRotationZ(fTheta/3.0f);
|
|
GFX3D::mat4x4 matWorld=GFX3D::Math::Mat_MultiplyMatrix(matRotateX,matRotateZ);
|
|
|
|
renderer.SetTransform(matWorld);
|
|
|
|
renderer.SetTexture(cubeTex);
|
|
//renderer.Render(cube.tris, GFX3D::RENDER_WIRE);
|
|
|
|
renderer.Render(cube.tris);
|
|
|
|
return true;
|
|
}
|
|
|
|
bool OnUserDestroy()override{
|
|
return true;
|
|
}
|
|
};
|
|
|
|
int main()
|
|
{
|
|
Graphics3DPGEX_Example demo;
|
|
if (demo.Construct(768, 480, 2, 2))
|
|
demo.Start();
|
|
|
|
return 0;
|
|
}
|
|
|