|
its finally done, if anyone needs it, here we go:
<pre>
class Sphere : public Entity
{
public:
IDirect3DVertexBuffer9* SphereVertexBuffer;
IDirect3DIndexBuffer9* SphereIndexBuffer;
int parallels;
int meridians;
float theta; // od 0 do pi
float phi; //od 0 to 2pi
int num_vertices;
int num_triangles;
void get_ime(){OutputDebugString("banana");};
Sphere(int *idd, std::string iime, int pparallels, int mmeridians, std::list<Entity*> *EEntity_list) : Entity(iime, *idd), parallels(pparallels), meridians(mmeridians){
float x,y,z;
theta=0; // od 0 do pi
phi=0;
int index=0;
num_vertices=2*(parallels-1)*(meridians)+2;
HR(gd3dDevice->CreateVertexBuffer(num_vertices* sizeof(VertexPos), D3DUSAGE_WRITEONLY,
0, D3DPOOL_MANAGED, &SphereVertexBuffer, 0));
VertexPos *v;
HR(SphereVertexBuffer->Lock( 0, 0, (void**)&v, 0 ))
for(int i=0;i<meridians;i++){ // iliti theta,manji kut
for(int j=0;j<2*parallels+1;j++){ // ili phi, veći kut od 0-2pi
if(j==0 || j == parallels ){
phi=phi+(D3DX_PI*2 / parallels)/2; //uvjeti za kapice
j++;
}
if(j==(parallels*2)) break;
x=cosf(theta)*sinf(phi);
if(fabs(x)<0.000001) x=0;
y=sinf(theta)*sinf(phi);
if(fabs(y)<0.000001) y=0;
z=cos(phi);
if(fabs(z)<0.000001) z=0;
v[index] = VertexPos(x,y,z);
index++;
phi=phi+(D3DX_PI*2 / parallels)/2;
}
phi=0;
theta=theta+(D3DX_PI/ meridians);
}
v[index]=VertexPos(0,0,1); //126 ako je 9, 9, a je//kapice iliti
index++;
v[index]=VertexPos(0,0,-1); //127
SphereVertexBuffer->Unlock();
//OutputDebugString(index);
HR(gd3dDevice->CreateIndexBuffer(12*meridians*(parallels-1) * sizeof(WORD), D3DUSAGE_WRITEONLY,
D3DFMT_INDEX16, D3DPOOL_MANAGED, &SphereIndexBuffer, 0));
WORD* k = 0;
int brojac=-1;
HR(SphereIndexBuffer->Lock(0, 0, (void**)&k, 0));
for(int i=1;i<meridians+1;i++){
k[++brojac]=num_vertices-2;
(i==meridians) ? (k[++brojac]=2*(parallels-1)-1):(k[++brojac]=i*2*(parallels-1)); //kapica gore, prednja
k[++brojac]=i*2*(parallels-1)-2*(parallels-1);
k[++brojac]=num_vertices-2;
(i==meridians) ? (k[++brojac]=0):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-1); //kapica gore, preko puta
k[++brojac]=i*2*(parallels-1)-1;
for(int j=0;j<parallels-2;j++){
k[++brojac]=i*2*(parallels-1)-2*(parallels-1)+j;
(i==meridians) ? (k[++brojac]=2*(parallels-1)-j-1):(k[++brojac]=i*2*(parallels-1)+j); //prednji, lijevo gore trokut
k[++brojac]=i*2*(parallels-1)-2*(parallels-1)+j+1;
(i==meridians)?(k[++brojac]=2*(parallels-1)-j-1):(k[++brojac]=i*2*(parallels-1)+j); //prednji, suprotni
(i==meridians)?(k[++brojac]=2*(parallels-1)-j-2):(k[++brojac]=i*2*(parallels-1)+j+1);
k[++brojac]=i*2*(parallels-1)-2*(parallels-1)+j+1;
k[++brojac]=i*2*(parallels-1)-1-j;
(i==meridians)?(k[++brojac]=j):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-1-j); //stražnji, lijevo gore trokut
k[++brojac]=i*2*(parallels-1)-2-j;
(i==meridians)?(k[++brojac]=j):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-1-j);
(i==meridians)?(k[++brojac]=j+1):(k[++brojac]=i*2*(parallels-1)+2*(parallels-1)-2-j); //stražnji, suprotni
k[++brojac]=i*2*(parallels-1)-2-j;
}
k[++brojac]=num_vertices-1;
k[++brojac]=i*2*(parallels-1)-(parallels-1)-1; //kapica dolje, prednja
(i==meridians) ? (k[++brojac]=(parallels-1)):(k[++brojac]=i*2*(parallels-1)+(parallels-1)-1);
k[++brojac]=num_vertices-1;
k[++brojac]=i*2*(parallels-1)-(parallels-1); //kapica dolje, preko puta
(i==meridians) ? (k[++brojac]=(parallels-1)-1):(k[++brojac]=i*2*(parallels-1)+(parallels-1));
}
HR(SphereIndexBuffer->Unlock());
EEntity_list->push_back(this);
++(*idd); //*idd=*idd+1 <-isto kao i navedeno
}
void Render(){
HR(gd3dDevice->SetStreamSource(0, SphereVertexBuffer, 0, sizeof(VertexPos)));
HR(gd3dDevice->SetIndices(SphereIndexBuffer));
HR(gd3dDevice->DrawIndexedPrimitive( D3DPT_TRIANGLELIST,0,0,num_vertices,0,4*meridians*(parallels-1)));
//HR(gd3dDevice->DrawPrimitive(D3DPT_POINTLIST,0,144));
//HR(gd3dDevice->DrawIndexedPrimitive( D3DPT_POINTLIST,0,0,200,0,288));
}
};
</pre>
|
|
|
|
|
I was looking for something like this. Awesome. Thanks for all the hard work
|
|
|
|
|
im glad i could be helpful
|
|
|
|
|
I have read the solution to the issue and I was also in the process of learning how to make 3D's. I checked the code and will be trying this one out. I hope you don't mind. Thanks a lot!
|
|
|
|
|
ofcourse i dont mind, ima glad.
By the way there are a few limitations you need to be aware of.
First the smallest values for meridians and parallels are 2 both, which makes sense since its not possible to draw a sphere any simpler than that. With 2,2 values, you get a double tetrahedron. The max values are about 180, 180, which makes a pretty detailed sphere, and ALOT of triangles, so it cripples the framerate. This is due to float precision, it can be solved in certain ways, but i doubt you will need a sphere that detailed.
Anyway, have fun.
|
|
|
|
|
hello,
i'm new to openGL, and i'm trying to build a color lookup table of size 265
is there any thing wrong in my code??
// i define the array in header
GLfloat color_table[256][4];
void BuildColorLookUpTable()
{
for(INT i = 0; i < 256; i++)
{
GLfloat red=i/255;
GLfloat green=0;
GLfloat blue=1-i/255;
color_table[i][0] = 0;
color_table[i][0] = red;
color_table[i][0] = green;
color_table[i][0] = blue;
glutSetColor(i, red, green, blue);
}
}
also, can anyone pls give me some guides
thanks
|
|
|
|
|
How is your code acting versus what you expected?
Also, you might ask yourself what i/255 computes to?
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
i used i/255 to compute the red value,i didn't test my program yet
but my question was is this enough to build the lookup table or I should use
some gl commands to enable the index color mode??
can i use now glindex()??
thanks
|
|
|
|
|
I never used Glut when I was playing with OpenGL but it appears like if you're in color index mode that should setup the table. There might even be a default table already there. I'm not sure why you're maintaining the array of colors, when you can access Glut's color table once you've set it.
You're trying to setup up the table with green a constant zero. Red varying linearly from zero to one and blue being one minus red. However, the reason I asked you to think about what i/255 evaluates to means that's not what you're going to get. Your color table will be considerably more boring.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
thanks, i solved the problem of th table
but i have another question pls
i implement this function to render the face normal of the mesh but when i debug
i found that the program doesn't enter the loop at all and i get this in the watch of the debug when
i type i: i CXX0017: Error: symbol "i" not found
inline void CMesh::RenderFaceNormals()
{
float t=0.5;
CVector v0,v1;
for(int i=0 ; i<get_numoffaces();i++)
{
="" v0="(verts[faces[i]-">get_v0()]->get_gp()+ verts[faces[i]->get_v1()]->get_gp()+ verts[faces[i]->get_v2()]->get_gp() )/3;
v1 = t * faces[i]->get_normal();
glBegin(GL_LINES);
glVertex3f(v0.X(), v0.Y(), v0.Z()); // origin of the line
glVertex3f(v1.X(), v1.Y(), v1.Z()); // ending point of the line
glEnd();
}
}
it seems that my program doesn't see i??
can anyone help me??
|
|
|
|
|
As written above, I'm not sure how this compiled. Your for loop is malformed by missing the closing parenthesis at the very least and the second semicolon.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
No i'm sure there is no syntax errors, the error in the loop header only appear when i copy
from my program
anyone have solutions for my problem????
inline void CMesh::RenderFaceNormals()<br />
{<br />
float t=0.5;<br />
CVector v0,v1;<br />
<br />
for(int i=0 ; i< get_numOfFaces() ;i++)<br />
{<br />
v0 = (verts[faces[i]->get_v0()]->get_gp()+ verts[faces[i]->get_v1()]->get_gp()+ verts[faces[i]->get_v2()]->get_gp() )/3;<br />
v1 = t * faces[i]->get_normal();<br />
<br />
glBegin(GL_LINES);<br />
glVertex3f(v0.X(), v0.Y(), v0.Z());
glVertex3f(v1.X(), v1.Y(), v1.Z());
glEnd();<br />
}<br />
}
|
|
|
|
|
What compiler and version are you using?
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
Microsoft Visual Studio 2005
|
|
|
|
|
Then it should be ok with defining the loop variable inside the for header. But to determine if something else is causing a side effect, try this:
int i;
for (i = 0 ; whatever your condition was ; i++)
{
your stuff
}
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
Thanks Tim very much for ur help
i solve the problem, the problem was that my project was in release mode so i changed it now to debuge mode and it works well
i really appreciate your help
|
|
|
|
|
I'm not sure how switching to debug compile from release "fixes" the problem. Usually then that happens, you have a problem with unitialized memory that debug mode automatically sets to zero or you're using something like an assert macro that is compiled out in release mode and leaves a hole in your code but lets debug mode work.
"Republicans are the party that says government doesn't work and then they get elected and prove it." -- P.J. O'Rourke I'm a proud denizen of the Real Soapbox[ ^] ACCEPT NO SUBSTITUTES!!!
|
|
|
|
|
Hi,
if the release build also works well, then you can claim you solved the problem.
if not, you just closed your eyes. switching to debug mode does not solve anything that turning off the computer would not solve.
if you need some advice on fixing release problems, read Debugging Release Mode Problems[^] and this[^].
Luc Pattyn [Forum Guidelines] [My Articles]
The quality and detail of your question reflects on the effectiveness of the help you are likely to get.
Show formatted code inside PRE tags, and give clear symptoms when describing a problem.
|
|
|
|
|
Hi...
This is graphics related.I need to draw a map .I have the latitude longitude values of it .I was able to map(w-to v) these to screen coordinates and then draw the map.The problem i need help with is how do i do the reverse,because i need to show the latitude longitude values as the mouse moves over the map.For the initial case its simple,just rearrangement of window to view port mapping formula .i.e.,
u = (x-xmin)* sx+ umin
v = (y-ymin)* sy + vmin
But once the zoom and pan operations are applied on the map, I don't know how to get the latitude longitude values from the screen coordinate.
If some one knows how to solve this ,Please help me
Thanks in advance
|
|
|
|
|
Hi,
I want to develop a window like GUI for my appplication(which is running on OpenSUSE).
Are there any tools or libraries that I can use ?
But the condition is that I can't use GPL/LGPL licensed tools/libraries.
Anybody, please reply asap.
Regards,
Manik
|
|
|
|
|
If you can't use any GPL stuff, you can't use Linux, or GNU, or X-Windows.
How about you write your own OS, compiler, Windowing system etc?
|
|
|
|
|
If I bought the license for OpenSuse, doesnt that include X Windows and stuff ?
|
|
|
|
|
I doubt you bought a license for OpenSuse. You MAY have bought a DVD, but that's not a license. Anyone can download and use it legally for free.
Anyway, all Linux distributions are built using the GNU toolchain (gcc etc) which are GPL (or similar).
Who decided you couldn't use GPL code? Do they know what GPL software means?
|
|
|
|
|
Does anyone know a way to disable the ClearType font rendering via a system function?
We render a lot of text (monochrome) into memory bitmaps and dibs and it takes forever. If we disable ClearType via the control panel the process is very, very fast but the users screen looks like crap.
Our apps execute on both XP and Vista.
The user wouldn’t even mind if the screen looked bad during the process and reverted back to cleartype after the process. Any ideas?
Thanks in advance
Tony Teveris
Gerber Scientific Products
Senior Software Engineer
Phone: 860 648 8151
Fax: 860 648 8214
83 Gerber Road West
South Windsor, CT 06074
|
|
|
|
|
See if anything here[^] helps.
Henry Minute
Do not read medical books! You could die of a misprint. - Mark Twain
Girl: (staring) "Why do you need an icy cucumber?"
“I want to report a fraud. The government is lying to us all.”
|
|
|
|
|