Trying to write a small class that will draw a 3D sphere primitive.
What I'm doing now is working, however, I cannot get the sphere to rotate around itself unless it is very close to the origin of my world.
This code is not in a speed-critical section - all spheres are generated in the constructor - all objects are created prior to rendering the world. This will be called once for every sphere (planet) in the world (universe) during the load process.
Here is the code to create the base circle:
If you find errors in the code, I posted wrong. There are no warnings or errors when I compile the project.
void Sphere::Sphere(Vector center,double lx,double ly,double lz,short NumFacets,short radius)
SphereCenter.Local=center; //SphereCenter is type vertex in
Vertex *BaseCircle=new Vertex[NumFacets];
for (int i=0;i<NumFacets;i++)
BaseCircle[i].Local=temp; //operator handled by vector class
//Now translate lx,ly,lz on x,y,z
//rotate this circle ax,ay, az radians
//Transform using local space to get world space
//Append result to vertexes for sphere
//Too lengthy to post here
The translation to world coords causes them to rotate around lx-origin, ly-origin, lz-origin, not around their actual centers.
I think the problem is that my sphere is not centered around the x,y,z axes. This would cause the sphere to rotate around that point, rather than it's center. However, I've also tried to create a sphere using x,z and y,z, but the same thing happens.
How do I rotate these spheres around their central point, rather than around a point in space? I don't want them to orbit, they need to rotate.
An algorithm to create the approx of a sphere around point lx,ly,lz at radius r and facets f is what I'm looking for.