rolling cube
This commit is contained in:
18
src/main.cpp
18
src/main.cpp
@@ -178,7 +178,7 @@ int main() {
|
|||||||
|
|
||||||
Shape plane { shader, shapes.at("square") };
|
Shape plane { shader, shapes.at("square") };
|
||||||
plane.init();
|
plane.init();
|
||||||
plane.translate(glm::vec3 { 0.0f, -1.0f, 0.0f });
|
plane.translate(glm::vec3 { 0.0f, -0.75f, 0.0f });
|
||||||
plane.rotate(glm::radians(90.0f), glm::vec3 { 1.0f, 0.0f, 0.0f });
|
plane.rotate(glm::radians(90.0f), glm::vec3 { 1.0f, 0.0f, 0.0f });
|
||||||
plane.scale(glm::vec3 { 1.0f } * 100.0f);
|
plane.scale(glm::vec3 { 1.0f } * 100.0f);
|
||||||
|
|
||||||
@@ -188,6 +188,11 @@ int main() {
|
|||||||
long unsigned int frame { 0 };
|
long unsigned int frame { 0 };
|
||||||
double last_frame_time { 0 };
|
double last_frame_time { 0 };
|
||||||
|
|
||||||
|
struct {
|
||||||
|
float x;
|
||||||
|
float z;
|
||||||
|
} cube_last_pos { .x = 0.0f, .z = 0.0f };
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
const double current_time { glfwGetTime() };
|
const double current_time { glfwGetTime() };
|
||||||
delta = current_time - last_frame_time;
|
delta = current_time - last_frame_time;
|
||||||
@@ -201,6 +206,7 @@ int main() {
|
|||||||
process_keyboard_input(window);
|
process_keyboard_input(window);
|
||||||
|
|
||||||
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
glClearColor(0.5f, 0.5f, 0.5f, 1.0f);
|
||||||
|
// glClearColor(0.0f, 0.0f, 1.0f, 1.0f);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
glm::mat4 view { camera.get_view_matrix() };
|
glm::mat4 view { camera.get_view_matrix() };
|
||||||
@@ -222,7 +228,15 @@ int main() {
|
|||||||
plane.draw();
|
plane.draw();
|
||||||
|
|
||||||
shader->set_vec4("color", glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f });
|
shader->set_vec4("color", glm::vec4 { 1.0f, 1.0f, 1.0f, 1.0f });
|
||||||
cube.rotate(glm::radians(1.0f), glm::vec3 { 0.0f, 1.0f, 0.0f });
|
cube.reset_transform();
|
||||||
|
const float x { static_cast<float>(std::cos(current_time)) };
|
||||||
|
const float z { static_cast<float>(std::sin(current_time)) };
|
||||||
|
cube.translate(glm::vec3 { x, 0.0f, z } );
|
||||||
|
const float dx { x - cube_last_pos.x };
|
||||||
|
const float dz { z - cube_last_pos.z };
|
||||||
|
cube.rotate(glm::radians(-90.0f), glm::vec3 { dx, 0.0f, dz });
|
||||||
|
cube_last_pos.x = x;
|
||||||
|
cube_last_pos.z = z;
|
||||||
cube.draw();
|
cube.draw();
|
||||||
|
|
||||||
const double time_since_last_frame { glfwGetTime() - last_frame_time };
|
const double time_since_last_frame { glfwGetTime() - last_frame_time };
|
||||||
|
|||||||
Reference in New Issue
Block a user