D3DXVECTOR4 Temp;
D3DXMATRIX rot;
for(int j =180;j >= 0; j -= 12)
{
for(int i = 360;i>=0;i-= 12 )
{
D3DXMatrixRotationY(&rot,D3DXToRadian(j));
D3DXVec3Transform(&Temp,&D3DXVECTOR3(cos(D3DXToRadian(i)) * Radius,
sin(D3DXToRadian(i)) * Radius,0),&rot);
CircleList.push_back(PCVertex(D3DXVECTOR3
(Temp.x,Temp.y,Temp.z),D3DCOLOR_XRGB(255,255,255)));
}
}
Drawing a better(or more efficient) Sphere
i've been working on procedurally generating a sphere, which i have done, but I took a short cut, and i'd liek to figure out a less hacky way to do it, here's an example of the code
basiclly i plot a series of circles, proforming a rotation to every vertex, but thats a lot of calculations for every vertex
does anyone see know of a simpler technique for logically rotating the circle around the Y axis?
thanks
because then I wouldn't learn anything :) I figure computational geometry is an important aspect in computer graphics, and the more practice and experience I get, the better off I am
Well if you insist on knowing things! ;)
First off, don't bother with all the matrix transform math just to place a vertex - use some trigonometry to work out the position from your two angle loop variables. If you're stuck, think of a slice through the sphere as a circle with radius of cos(latitude) (latitude being the angle from the 'equator' of course) and then use the 'longitude' to place each vertex on that ring. But given that this is probably an 'offline' operation (i.e. you're not regenerating the sphere each frame I assume?) the efficiency probably isn't a massive issue.
More problematic is that you're creating degenerate vertices at the poles. Consider the poles as a special case and just generate one vertex for them, then connect that vertex to the first proper 'ring' of the sphere using a triangle-fan arrangement. Determining correct index buffer ordering might take some thought.
More generally though, while I agree it's a useful exercise to create procedural geometry I wouldn't get too caught up in it without good reason. An equally valid learning exercise would be to import data using a standard file format created by a 3D modelling package.
First off, don't bother with all the matrix transform math just to place a vertex - use some trigonometry to work out the position from your two angle loop variables. If you're stuck, think of a slice through the sphere as a circle with radius of cos(latitude) (latitude being the angle from the 'equator' of course) and then use the 'longitude' to place each vertex on that ring. But given that this is probably an 'offline' operation (i.e. you're not regenerating the sphere each frame I assume?) the efficiency probably isn't a massive issue.
More problematic is that you're creating degenerate vertices at the poles. Consider the poles as a special case and just generate one vertex for them, then connect that vertex to the first proper 'ring' of the sphere using a triangle-fan arrangement. Determining correct index buffer ordering might take some thought.
More generally though, while I agree it's a useful exercise to create procedural geometry I wouldn't get too caught up in it without good reason. An equally valid learning exercise would be to import data using a standard file format created by a 3D modelling package.
thanks for the help, I knew it would be a trig problem, I'm still getting a handle on 3D geometry so it's hard to visualiz, and no I wouldn't be updating it.
I've also been working on pulling geometry from 3D File's(I wrote an MD2 loader, i'll probobly start on an MD3 or MD5 loader soon enough), as well as getting some practice ripping data from a D3DXMESH through Frank Luna's 2nd Ed. directX9 book.
I'm gonna look at it in the way you suggested, and see if I can pick up on it, and I've resigned myself to the fact that generating indices is gonna be a challenge, but a challenge is the path to growth.
Thanks for the help
I've also been working on pulling geometry from 3D File's(I wrote an MD2 loader, i'll probobly start on an MD3 or MD5 loader soon enough), as well as getting some practice ripping data from a D3DXMESH through Frank Luna's 2nd Ed. directX9 book.
I'm gonna look at it in the way you suggested, and see if I can pick up on it, and I've resigned myself to the fact that generating indices is gonna be a challenge, but a challenge is the path to growth.
Thanks for the help
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement