Rewrite spheres render logic
This commit is contained in:
parent
118e8d574d
commit
bebee39768
@ -21,6 +21,8 @@ const float initialSpeed = 5.0f;
|
||||
const float initialAngle = 45.0f;
|
||||
const float ballRadius = 0.5;
|
||||
|
||||
const int numberOfPointsOnCircle = 120;
|
||||
|
||||
const int windowWidth = 1920;
|
||||
const int windowHeight = 800;
|
||||
|
||||
@ -395,31 +397,30 @@ void rungeKuttaStep(Ball &ball, float dt) {
|
||||
}
|
||||
|
||||
void setupSphereBuffer() {
|
||||
int slices = 20;
|
||||
int stacks = 20;
|
||||
std::vector<float> vertices;
|
||||
|
||||
for (int i = 0; i <= stacks; ++i) {
|
||||
float V = i / (float) stacks;
|
||||
float phi = V * M_PI;
|
||||
std::vector<glm::vec3> vertices;
|
||||
|
||||
for (int j = 0; j <= slices; ++j) {
|
||||
float U = j / (float) slices;
|
||||
float theta = U * (M_PI * 2);
|
||||
float angle = 360.0f / numberOfPointsOnCircle;
|
||||
|
||||
float x = cosf(theta) * sinf(phi);
|
||||
float y = cosf(phi);
|
||||
float z = sinf(theta) * sinf(phi);
|
||||
int triangleCount = numberOfPointsOnCircle - 2;
|
||||
|
||||
vertices.push_back(x * ballRadius);
|
||||
vertices.push_back(y * ballRadius);
|
||||
vertices.push_back(z * ballRadius);
|
||||
std::vector<glm::vec3> temp;
|
||||
// positions
|
||||
for (int i = 0; i < numberOfPointsOnCircle; i++)
|
||||
{
|
||||
float currentAngle = angle * i;
|
||||
float x = ballRadius * cos(glm::radians(currentAngle));
|
||||
float y = ballRadius * sin(glm::radians(currentAngle));
|
||||
float z = 0.0f;
|
||||
|
||||
// Dodanie normalnych wektorów
|
||||
vertices.push_back(x);
|
||||
vertices.push_back(y);
|
||||
vertices.push_back(z);
|
||||
}
|
||||
temp.push_back(glm::vec3(x, y, z));
|
||||
}
|
||||
|
||||
for (int i = 0; i < triangleCount; i++)
|
||||
{
|
||||
vertices.push_back(temp[0]);
|
||||
vertices.push_back(temp[i + 1]);
|
||||
vertices.push_back(temp[i + 2]);
|
||||
}
|
||||
|
||||
glGenVertexArrays(1, &VAO_SPHERES);
|
||||
@ -428,7 +429,7 @@ void setupSphereBuffer() {
|
||||
glBindVertexArray(VAO_SPHERES);
|
||||
|
||||
glBindBuffer(GL_ARRAY_BUFFER, VBO_SPHERES);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(float), vertices.data(), GL_STATIC_DRAW);
|
||||
glBufferData(GL_ARRAY_BUFFER, vertices.size() * sizeof(glm::vec3), vertices.data(), GL_STATIC_DRAW);
|
||||
|
||||
// Współrzędne wierzchołków
|
||||
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 6 * sizeof(float), (void*)0);
|
||||
|
Loading…
Reference in New Issue
Block a user