PDA

View Full Version : grasping and moving



beet6
03-27-2002, 12:15 PM
I want to grasp an object (a ball) and move it with a virtual hand. With glLoadMatrixf(m), the coordinate systems can switch between target system and hand system.
But it looks jerky and shaky. some idea?
Thank you very much.

some code:

void drawball()
{
glPushMatrix();
glLoadIdentity();
glLoadMatrixf(m);
glTranslatef(Tvec0,Tvec1,Tvec2); //this vector is from ball to original point of the coordinate sys.
glutSolidSphere(1.0,40,40);
glGetFloatv(GL_MODELVIEW_MATRIX,m0);
Ballcen.x=m0[12]; //x_value
Ballcen.y=m0[13]; //y_value
Ballcen.z=m0[14]; //z_value
glPopMatrix();
}

void graspFunc(int val)
{
m_bGrasped=ptData.gT.isGrasped();
if(m_bGrasped){
for(int i=0;i<16;i++)
m[i]=m1[i];
Tvec0=Ballcen.x-palmX;
Tvec1=Ballcen.y-palmY;
Tvec2=Ballcen.z-palmZ;
}
else
{
for(i=0;i<16;i++)
m[i]=m0[i];
Tvec0=Tvec1=Tvec2=0.0;
}
} //this grasp func called by glutTimerFunc()

.........................................
partal from Display()
.........................................
// draw palm
glTranslatef(Tx0,Tx1,Tx2);
glRotatef(handR,axisX,axisY,axisZ);
//m1 is the matrix for hand palm
//when the balled grasped, load this
//m1 to Drawball() function
glGetFloatv(GL_MODELVIEW_MATRIX,m1);
glPushMatrix();
glScalef(3.0,0.8,3.0);
glutSolidCube(1.0);
glPopMatrix();

...


thanks again
beet

beet6
03-27-2002, 07:04 PM
any GL gurus help me please
Thanks