Drawing created sphere on screen

Tutorials concerning the OpenGL® ES cross-platform API for full-function 2D and 3D graphics on the Google-Android platform.

Drawing created sphere on screen

Postby Hachaso » Sun May 24, 2009 3:52 pm

Hi!

I found some tutorial code how to create a sphere using Opengl API's.

Code: Select all
typedef struct
{
int X;
int Y;
int Z;

double U;
double V;
}VERTICES;

void CreateSphere (double R, double H, double K, double Z) {
int n;
double a;
double b;

n = 0;

for( b = 0; b <= 90 - space; b+=space){
for( a = 0; a <= 360 - space; a+=space){

VERTEX[n].X = R * sin((a) / 180 * PI) * sin((b) / 180 * PI) - H;
VERTEX[n].Y = R * cos((a) / 180 * PI) * sin((b) / 180 * PI) + K;
VERTEX[n].Z = R * cos((b) / 180 * PI) - Z;
VERTEX[n].V = (2 * b) / 360;
VERTEX[n].U = (a) / 360;
n++;

VERTEX[n].X = R * sin((a) / 180 * PI) * sin((b + space) / 180 * PI) - H;
VERTEX[n].Y = R * cos((a) / 180 * PI) * sin((b + space) / 180 * PI) + K;
VERTEX[n].Z = R * cos((b + space) / 180 * PI) - Z;
VERTEX[n].V = (2 * (b + space)) / 360;
VERTEX[n].U = (a) / 360;
n++;

VERTEX[n].X = R * sin((a + space) / 180 * PI) * sin((b) / 180 * PI) - H;
VERTEX[n].Y = R * cos((a + space) / 180 * PI) * sin((b) / 180 * PI) + K;
VERTEX[n].Z = R * cos((b) / 180 * PI) - Z;
VERTEX[n].V = (2 * b) / 360;
VERTEX[n].U = (a + space) / 360;
n++;

VERTEX[n].X = R * sin((a + space) / 180 * PI) * sin((b + space) / 180 * PI) - H;
VERTEX[n].Y = R * cos((a + space) / 180 * PI) * sin((b + space) / 180 * PI) + K;
VERTEX[n].Z = R * cos((b + space) / 180 * PI) - Z;
VERTEX[n].V = (2 * (b + space)) / 360;
VERTEX[n].U = (a + space) / 360;
n++;

}
}
}



The problem is that the calculated values of X, Y and Z are integers.

I would like to use glVertexPointer to be able do draw this sphere.
Could someone please help me here.
Do I need to do something with the calculated values to be able to use glVertexPointer and glDrawElements?

Thanks
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Top

Postby fusion » Sun May 24, 2009 7:39 pm

Just cast it to a a float.

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2. int i = 1;
  3.  
  4. float f = (float)i;
  5.  
  6.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4
fusion
Freshman
Freshman
 
Posts: 3
Joined: Sun May 24, 2009 9:42 am

Postby Hachaso » Sun May 24, 2009 8:59 pm

The problem is that some of the values or higher then 1.0f.

Do I need to convert the values somehow to fit the screen coordinates ?

Thanks
Hachaso
Developer
Developer
 
Posts: 43
Joined: Mon Jan 26, 2009 11:44 am

Top

Return to Android 2D/3D Graphics - OpenGL Tutorials

Who is online

Users browsing this forum: No registered users and 3 guests