예제 #1
0
void ShapeDrawer::drawObject(const btCollisionObject* object)
{
    if(object->getInternalType() ==  btCollisionObject::CO_RIGID_BODY) {
        drawRigidBody(btRigidBody::upcast(object));
    }
    else if(object->getInternalType() ==  btCollisionObject::CO_SOFT_BODY) {
        drawSoftBody(btSoftBody::upcast(object));
    }
}
void TestAppRigidBody::draw(){
    //printf( " ==== frame %i \n", frameCount );
    glClearColor( 0.5f, 0.5f, 0.5f, 1.0f );
	glClear( GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT );

    int perFrame = 1;
	double dt    = 0.01;

	// ---- soft body test
    //truss.dt   = dt;
    //truss.damp = 0.0;
    //for(int itr=0; itr<perFrame; itr++){ truss.step(); }
    //drawTruss( &truss, 1.0, 1.0, false );

    // ---- RidigBody basics - drag
    Vec3d gdp,gv,gf;
    rb.clean_temp();
    rb.velOfPoint ( {2.0,5.0,6.0}, gv, gdp );
    gf.set_mul(gv, -0.01 );
    rb.apply_force( gf, gdp );
    rb.move(dt);
    rb.pos.set(0.0);
    rb.vel.set(0.0);

    glPushMatrix();
    glTranslatef(-5.0,0.0,0.0);
    glScalef(0.6,0.6,0.6);
    drawRigidBody( rb, npoints, (Vec3d*)points );
    glColor3f(1.0f,1.0f,1.0f);
    Draw3D::drawPointCross( gdp, 0.2 );
    Draw3D::drawVecInPos  ( gf*1000.0, gdp );
    glPopMatrix();


    // ---- RigidBody springs
	for(int itr=0; itr<perFrame; itr++){
        for(SpringConstrain * sp : springs){
            sp->apply();
        }
        for( Object3D * o : objects ){
            RigidBody * rb = o->controler;
            if(rb){
                rb->vel.mul( 1-dt*0.2 );
                rb->L.  mul( 1-dt*0.2 );
                rb->apply_force({0,-9.81,0},{0.0,0.0,0.0});
                rb->move_RigidBody(dt);
                rb->clean_temp();
            }
        }
	}
	for( Object3D * o : objects ){
        if(o->controler){
            o->bounds.pos         = o->controler->pos;
            //o->bounds.orientation = o->controler->rotMat;
            o->bounds.orientation.setT(o->controler->rotMat);
        };
	}
    glEnable( GL_LIGHTING );
    glEnable(GL_DEPTH_TEST);
    for( Object3D * o : objects ){
        if (o->shape){
            float glMat[16];
            glPushMatrix();
            Draw3D::toGLMat( o->bounds.pos, o->bounds.orientation, o->bounds.span, glMat );
            glMultMatrixf( glMat );
            glCallList( o->shape );
            glPopMatrix();
        }
    }
    glDisable( GL_LIGHTING );
    for(SpringConstrain * sp : springs ){
        Vec3d gp1,gp2,f;
        sp->getPoints( gp1, gp2 );
        f = sp->getForce( gp1, gp2 );
        glColor3f(1.0f,1.0f,1.0f); Draw3D::drawLine( gp1, gp2 );
        //glColor3f(1.0f,0.0f,0.0f); Draw3D::drawVecInPos( f, gp1 );
    }
    Draw3D::drawAxis(1.0);


};