debug print for character coords

This commit is contained in:
ohsqueezy 2023-06-19 20:32:14 -04:00
parent 4e03605f39
commit d371886a66
3 changed files with 30 additions and 6 deletions

View File

@ -38,7 +38,8 @@
"fps": ["CTRL", "f"],
"skip forward": ["CTRL", "SHIFT", "right"],
"skip backward": ["CTRL", "SHIFT", "left"],
"memory": ["CTRL", "SHIFT", "m"]
"memory": ["CTRL", "SHIFT", "m"],
"coords": ["CTRL", "SHIFT", "c"]
},
"log":

View File

@ -177,6 +177,7 @@ void Cakefoot::respond(SDL_Event& event)
field_of_view_y = glm::radians(100.0f);
}
}
else if (event.type == SDL_MOUSEBUTTONUP || sb::Delegate::compare_cancel(event, "any"))
{
/* End character acceleration */
@ -186,6 +187,7 @@ void Cakefoot::respond(SDL_Event& event)
character.accelerating = false;
}
}
else if (event.type == SDL_MOUSEMOTION || event.type == SDL_MOUSEBUTTONDOWN || sb::Delegate::compare(event, "any"))
{
/* Start character acceleration */
@ -232,20 +234,24 @@ void Cakefoot::respond(SDL_Event& event)
SDL_SetCursor(SDL_GetDefaultCursor());
}
}
else if (sb::Delegate::compare(event, "fps"))
{
configuration()["display"]["fps"] = !configuration()["display"]["fps"];
}
else if (sb::Delegate::compare(event, "skip forward"))
{
curve_index++;
character.reset(curve());
}
else if (sb::Delegate::compare(event, "skip backward"))
{
curve_index--;
character.reset(curve());
}
else if (sb::Delegate::compare(event, "reset"))
{
field_of_view_y = 2 * glm::atan(1.0 / camera_position.z);
@ -253,6 +259,7 @@ void Cakefoot::respond(SDL_Event& event)
curve_index = 0;
character.reset(curve());
}
/* Taken from mallinfo man page, log a profile of the memory when the command is sent. */
else if (sb::Delegate::compare(event, "memory"))
{
@ -276,6 +283,7 @@ void Cakefoot::respond(SDL_Event& event)
/* Loop through the map, and print each value. */
std::ostringstream message;
int first_column = 40, second_column = 12, count = 0;
message << std::endl;
for (std::pair<std::string, int> malloc_info_entry : malloc_map)
{
message << std::setw(first_column) << malloc_info_entry.first << std::setw(second_column) << std::setprecision(2)
@ -287,6 +295,17 @@ void Cakefoot::respond(SDL_Event& event)
}
sb::Log::log(message);
}
/* Print the coordinates of the cake sprite in all coordinate spaces */
else if (sb::Delegate::compare(event, "coords"))
{
std::ostringstream message;
glm::vec2 translation = sb::wrap_point(character.position, {-curve().aspect, -1.0f}, {curve().aspect, 1.0f});
message << std::fixed << std::setprecision(2) << "Character coords: unwrapped " << character.position << ", wrapped " << translation
<< ", clip " << world_to_clip(translation, projection, view) << ", ndc " << world_to_ndc(translation, projection, view)
<< ", window " << world_to_window(translation, projection, view, window_box().size());
sb::Log::log(message);
}
}
void Cakefoot::run()
@ -324,11 +343,8 @@ void Cakefoot::update(float timestamp)
/* Transformation from camera space to clip space. */
projection = glm::perspective(field_of_view_y, window_box().aspect(), 0.1f, 100.0f);
/* Cake coordinates in translation space, clip space, NDC space, and window space. The last three are for debugging. */
/* Cake coordinates wrapped */
glm::vec2 cake_translation = sb::wrap_point(character.position, {-curve().aspect, -1.0f}, {curve().aspect, 1.0f});
glm::vec4 cake_clip = projection * (view * glm::vec4{cake_translation.x, cake_translation.y, 0.0f, 1.0f});
glm::vec3 cake_ndc = glm::vec3{cake_clip.x, cake_clip.y, cake_clip.z} / cake_clip.w;
glm::vec2 cake_window = ((glm::vec2{cake_ndc.x, cake_ndc.y} + 1.0f) / 2.0f) * window_box().size();
/* Plane position vertices will be used for everything before the curve */
sb::Plane::position->bind("vertex_position", shader_program);

View File

@ -206,7 +206,8 @@ public:
* The existing transformation property will be reset to the identity matrix before this transformation is applied.
*
* @warning This function works differently than Model::transform(const glm::mat4&). To apply an arbitrary transformation
* without having the others applied as well, the other transformations should first be set to the identity matrix.
* without having the non-arbitrary transformations applied as well, the rotate, scale, and translate transformations should
* be set to the identity matrix.
*
* @param transformation optional additional transformation to apply
*/
@ -227,6 +228,8 @@ public:
*/
bool collide(const Sprite& sprite) const;
/*
*/
void bind_texture() const
{
if (textures().empty())
@ -239,12 +242,16 @@ public:
}
}
/*
*/
void bind_texture(GLuint texture_flag_uniform) const
{
glUniform1i(texture_flag_uniform, true);
bind_texture();
}
/*
*/
void draw(GLuint transformation_uniform, const glm::mat4 view = glm::mat4{1.0f}, const glm::mat4 projection = glm::mat4{1.0f}) const
{
glm::mat4 mvp = projection * view * transformation();