I have a question as I am analyzing the source of the circle drawing in OpenGL rotation.

Asked 2 years ago, Updated 2 years ago, 88 views

#define PI  3.1415926
#define No_theta    36
#define No_phi      18 


float theta, phi;
float delta_theta, delta_phi;
float start_theta, start_phi;

float Radius;

void Vertex_Generation(void)
{
    start_theta = 0.0;
    delta_theta = 2 * PI / No_theta; // how much are you gonna split? 2*PI = 2 pi radians meaning 360 degrees

    start_phi = -PI / 2.0;
    delta_phi = PI / (No_phi - 1);

    for (int j = 0; j < No_phi; j++)
    {   
        for (int i = 0; i < No_theta; i++)
        {
            theta = start_theta + i * delta_theta;
            phi = start_phi + j * delta_phi;
            ver[i][j].x = Radius * cos(phi) * cos(theta);
            ver[i][j].y = Radius * cos(phi) * sin(theta);
            ver[i][j].z = Radius * sin(phi);
            v_count++;
        }
    }
}

Hello, I am a student studying OpenGL alone. The source of the method of creating a circular circle (sphere) I'm asking you a question because there's something I don't understand while reading alone.

1. Meaning of the function Vertex_Generation. I don't know exactly what the function is. I don't know how to interpret Generation.Originally, it means generation, but I don't think it was used in that sense.How do I interpret it? I don't know if a function means that function, so just knowing the name of the function will help you understand it.

2. start_fi = -PI / 2.0; and delta_fi = PI / (No_fi - 1); are not sure what this means. I think start_phi and delta_phi are angles because we use the arc I don't know what role it plays.If you know well, please answer me Thank you

vs2017 opengl

2022-09-22 19:48

1 Answers

You're right to say that circular drawing creates coordinates through a negative repetition, right?

First of all, I'll answer your question

You can understand that the Vertex_Generation function is Vertex_Generate. So it's a function that's responsible for creating vertexes. It does not create the buffer itself to be raised by the graphic pipeline, but it is like putting a vertex (dot) that forms a sphere into a data structure in the Vector format of a ver array.

The start_phi is the starting angle when the point forming the sphere is obtained delta_phi indicates how much angle the PI (180 degrees) will be split. The reason for -PI in start_phi is to circulate in the direction of -PI/2 -> PI/2, which may vary depending on the developer's intention (0~PI, -PI~0 this way, the tool is made)

If you look at the wiki, there's a document on the https://ko.wikipedia.org/wiki/%EA%B5%AC%EB%A9%B4%EC%A2%8C%ED%91%9C%EA%B3%84 spherical coordinate system, and in the case of a trigonometric function, the formula may vary depending on how the coordinate axis is circulated. Wiki is a method of obtaining a value by moving theta value from 0 to PI based on the upper z-axis in the x-y plane, and the code you uploaded circulates the phi value to the -y to y-axis and turns the x-z plane around PI*2 (360 degrees) to obtain the value.

It hasn't been long since I studied in this field, but I think I made a phrase by referring to Wiki.

Rather than studying a sphere from scratch, it's easier to understand because if you draw a two-dimensional circle first and then approach the sphere, one more axis is added.


2022-09-22 19:48

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.