Last active
March 4, 2023 21:41
-
-
Save Infinitusvoid/90a61ebfc8af54882135b19fcc26aba5 to your computer and use it in GitHub Desktop.
C++ : random glm::vec3, float
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <cstdlib> // for rand and RAND_MAX | |
#include <glm/glm.hpp> | |
glm::vec3 generate_random_position(const glm::vec3& min_value, const glm::vec3& max_value) | |
{ | |
glm::vec3 result; | |
result.x = min_value.x + static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * (max_value.x - min_value.x); | |
result.y = min_value.y + static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * (max_value.y - min_value.y); | |
result.z = min_value.z + static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * (max_value.z - min_value.z); | |
return result; | |
} | |
float generate_random_float(const float min_value,const float max_value) | |
{ | |
return min_value + static_cast<float>(rand()) / static_cast<float>(RAND_MAX) * (max_value - min_value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment