|
|
|
#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.tris =
|
|
|
|
{
|
|
|
|
// SOUTH
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, WHITE },
|
|
|
|
{ 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, WHITE },
|
|
|
|
|
|
|
|
// EAST
|
|
|
|
{ 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 1.0f, 1.0f, 1.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, WHITE },
|
|
|
|
{ 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 1.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
|
|
|
// BOTTOM
|
|
|
|
{ 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, WHITE },
|
|
|
|
{ 1.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0.0f, WHITE },
|
|
|
|
|
|
|
|
};
|
|
|
|
olc::GFX3D::ConfigureDisplay();
|
|
|
|
|
|
|
|
|
|
|
|
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::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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
enum Direction{
|
|
|
|
RIGHT,
|
|
|
|
DOWN,
|
|
|
|
LEFT,
|
|
|
|
UP
|
|
|
|
};
|
|
|
|
|
|
|
|
struct Data{
|
|
|
|
int x,y;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
int main()
|
|
|
|
{
|
|
|
|
Graphics3DPGEX_Example demo;
|
|
|
|
if (demo.Construct(768, 480, 2, 2))
|
|
|
|
demo.Start();
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|