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

Method OnUserCreate

examples/TEST_Hardware3D.cpp:80–127  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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 {
118 float z = sin(float(x)) + cos(float(y));
119 cubes[y * 8 + x] = { float(x) - 4.0f, float(z), float(y) - 4.0f };
120 }
121
122
123 Clear(olc::VERY_DARK_BLUE);
124 HW3D_Projection(matProject.m);
125 HW3D_SetCullMode(olc::CullMode::CCW);
126 return true;
127 }
128
129 float fThetaX = 1;
130 float fThetaY = 2;

Callers

nothing calls this directly

Calls 6

CreateCubeFunction · 0.85
CreateMethod · 0.80
DecalMethod · 0.80
identityMethod · 0.45
SpriteMethod · 0.45
UpdateMethod · 0.45

Tested by

no test coverage detected