MCPcopy Create free account
hub / github.com/OneLoneCoder/olcPixelGameEngine / Quad3D

Class Quad3D

examples/TEST_Hardware3D.cpp:60–203  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

58
59
60class Quad3D : public olc::PixelGameEngine
61{
62public:
63 Quad3D()
64 {
65 sAppName = "Hardware3D Assetless Demo";
66 }
67
68 olc::mf4d matWorld;
69 olc::mf4d matView;
70 olc::mf4d matProject;
71
72 olc::Renderable texCube;
73 olc::utils::hw3d::mesh meshCube;
74 olc::utils::hw3d::mesh meshLightCube;
75
76 std::array<olc::vf3d, 64> cubes;
77 std::array<olc::vf3d, 3> lights;
78
79public:
80 bool OnUserCreate() override
81 {
82 float fAspect = float(GetScreenSize().y) / float(GetScreenSize().x);
83 float S = 1.0f / (tan(3.14159f * 0.25f));
84 float f = 1000.0f;
85 float n = 0.1f;
86
87 matProject(0, 0) = fAspect; matProject(0, 1) = 0.0f; matProject(0, 2) = 0.0f; matProject(0, 3) = 0.0f;
88 matProject(1, 0) = 0.0f; matProject(1, 1) = 1; matProject(1, 2) = 0.0f; matProject(1, 3) = 0.0f;
89 matProject(2, 0) = 0.0f; matProject(2, 1) = 0.0f; matProject(2, 2) = -(f / (f - n)); matProject(2, 3) = -1.0f;
90 matProject(3, 0) = 0.0f; matProject(3, 1) = 0.0f; matProject(3, 2) = -((f * n) / (f - n)); matProject(3, 3) = 0.0f;
91
92 matWorld.identity();
93 matView.identity();
94
95 // Create a unit cube, centered on origin
96 meshCube = olc::utils::hw3d::CreateCube({ 1,1,1 }, {-0.5, -0.5, -0.5});
97
98 // Creat another cube, smaller
99 meshLightCube = olc::utils::hw3d::CreateCube({ 0.5,0.5,0.5 }, { -0.25, -0.25, -0.25 });
100
101 // Why 2 cubes? the regular ones will have their vertex information recoloured
102
103 // Create texture (so we dont need to load anything)
104 texCube.Create(128, 128);
105 SetDrawTarget(texCube.Sprite());
106 Clear(olc::WHITE);
107 FillCircle(64, 64, 32, olc::BLACK);
108 FillCircle(64, 64, 24, olc::BLUE);
109 FillCircle(64, 64, 16, olc::RED);
110 FillCircle(64, 64, 8, olc::YELLOW);
111 SetDrawTarget(nullptr);
112 texCube.Decal()->Update();
113
114 // Position cubes nicely
115 for(int x=0; x<8; x++)
116 for (int y = 0; y < 8; y++)
117 {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected