void prepare() { texture = Image::createImage("assets/textures/test.jpg");
p1.color = RGBA(255, 0, 0, 255); p1.uv = math::vec2f(0.0f, 0.0f);
p2.color = RGBA(0, 255, 0, 255); p2.uv = math::vec2f(1.0f, 1.0f);
p3.color = RGBA(0, 0, 255, 255); p3.uv = math::vec2f(1.0f, 0.0f);
pos1 = {-1.5f, 0.0f, 0.0f, 1.0f}; pos2 = {1.5f, 0.0f, 0.0f, 1.0f }; pos3 = {0.0f, 2.0f, 0.0f, 1.0f };
perspectiveMatrix = math::perspective(60.0f, (float)WIDTH / (float)HEIGHT, 0.1f, 100.0f); screenMatrix = math::screenMatrix<float>(WIDTH, HEIGHT); }
float angle = 0.0f; float cameraPos = 5.0f; void Application::transform() { angle += 0.01f;
modelMatrix = math::translate(math::mat4f(1.0f), math::vec3f{ 0.5f, 0.0f, 0.0f }) * math::rotate(math::mat4f(1.0f), angle, math::vec3f{ 0.0f, 1.0f, 0.0f });
auto cameraModelMatrix = math::translate(math::mat4f(1.0f), math::vec3f{ 0.0f, 0.0f, cameraPos }); viewMatrix = math::inverse(cameraModelMatrix);
auto sp1 = perspectiveMatrix * viewMatrix * modelMatrix * pos1; auto sp2 = perspectiveMatrix * viewMatrix * modelMatrix * pos2; auto sp3 = perspectiveMatrix * viewMatrix * modelMatrix * pos3;
sp1 /= sp1.w; sp2 /= sp2.w; sp3 /= sp3.w;
sp1 = screenMatrix * sp1; sp2 = screenMatrix * sp2; sp3 = screenMatrix * sp3;
mV0.x = sp1.x; mV0.y = sp1.y;
mV1.x = sp2.x; mV1.y = sp2.y;
mV2.x = sp3.x; mV2.y = sp3.y; }
|