Jump to content
  • Advertisement
Sign in to follow this  
sv161

CD for ellipsoids

This topic is 3714 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Advertisement

Get vectors to the two corners of the triangle from one other point:
v0 = pt1 - pt0;
v1 = pt2 - pt0;

// Get the normal:
n = crossProduct(v1, v0);
normalise(n);

// Get d:
d = -dotProduct(n, pt0);

Share this post


Link to post
Share on other sites
Something's still wrong. ClsPt determines fine, but ClsPtPl is wrong.
	float d=-n.dot(v1);
float
dispN=disp.dot(n),
ElCtrDisp=c.dot(n)+d;
//Skip early out test to be able to visualize all data
//if(ElCtrDisp-1>dispN)
// return false;

//Using article "Appendix A"
float
k=-2*1/pow((n.Coords[0]*n.Coords[0]*sx*sx+
n.Coords[1]*n.Coords[1]*sy*sy+
n.Coords[2]*n.Coords[2]*sz*sz),0.5);
c_Vector3 ClsPt(k*n.Coords[0]*sx*sx/2.0,
k*n.Coords[1]*sy*sy/2.0,
k*n.Coords[2]*sz*sz/2.0);

glPushMatrix();
glTranslatef(c.Coords[0],c.Coords[1],c.Coords[2]);
glScalef(sx,sy,sz);
float amb[4]={0.1,0.1,0.1,1},dif[4]={0,1,0,1};
glEnable(GL_LIGHTING);
glDisable(GL_COLOR_MATERIAL);
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,amb);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,dif);
glutWireSphere(1,20,20);
glPopMatrix();
amb[0]=1;amb[1]=0;amb[2]=0;amb[3]=1;
dif[0]=0;dif[1]=1;dif[2]=0;dif[3]=1;
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT,amb);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE,dif);
glBegin(GL_TRIANGLES);
glNormal3fv(n.Coords);
glVertex3fv(v1.Coords);
glVertex3fv(v2.Coords);
glVertex3fv(v3.Coords);
glEnd();
glDisable(GL_LIGHTING);
glEnable(GL_COLOR_MATERIAL);
glBegin(GL_POINTS);
glVertex3fv((c+ClsPt).Coords);
glVertex3fv(c.Coords);
glEnd();
glBegin(GL_LINES);
glVertex3fv((c+ClsPt).Coords);
glVertex3fv(c.Coords);
glVertex3fv((v1+n).Coords);
glVertex3fv(v1.Coords);
glEnd();
glEnable(GL_LIGHTING);

float
elSep=ClsPt.dot(n)+d,
t=elSep/dispN;
//Skip early out test to be able to visualize all data
//if(t>1)
// return false;
c_Vector3 ClsPtPl=ClsPt-n*elSep;

glBegin(GL_POINTS);
glVertex3fv((c+ClsPtPl).Coords);
glEnd();
glBegin(GL_LINES);
glVertex3fv((c+ClsPtPl).Coords);
glVertex3fv((c+ClsPt).Coords);
glEnd();
...

Here is image what i got:
CD

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!