Exemplo n.º 1
0
// __________________________________________________________________________________________________
void KikiCellText::display ()
{
    loadId();

    glPushAttrib (GL_CURRENT_BIT | GL_ENABLE_BIT | GL_POLYGON_BIT);
    glPushMatrix ();
    
    glTranslatef (position[X], position[Y], position[Z]);
    KMatrix (current_orientation).glMultMatrix();
    if (offset)
    {
        glTranslatef ((*offset)[X], (*offset)[Y], (*offset)[Z]);
    }
    
    float factor = cell_height/height;
    glScalef (factor, factor, factor);
    
    if (picked)
    {
        glPushAttrib (GL_CURRENT_BIT);
        glDisable (GL_LIGHTING);
        glColor4f (1.0, 1.0, 1.0, 1.0);
        glPushMatrix();
        glScalef (width, height, 1);
        kDisplayWireCube (1.0);
        glPopMatrix();
        glEnable (GL_LIGHTING);
        glPopAttrib();
    }
    
    KikiText::display();
    
    glPopMatrix();
    glPopAttrib();
}
Exemplo n.º 2
0
// -------------------------------------------------------------------------------------------------------- 
void KPerspectiveProjection::rotate ( const GLfloat x, const GLfloat y, const GLfloat z )
{
    KVector savePos = getLookAtPosition();
    translate(-getPosition());
        
    KVector up   = getYVector();
    KVector look = getZVector();

    KMatrix rotxz; rotxz.rotate (x, 0.0, z);
    KMatrix roty;  roty.rotate  (0.0, y, 0.0);

    KVector yunit(0.0, 1.0, 0.0), zunit (0.0, 0.0, 1.0);

    KVector lookperp = look.perpendicular (yunit); // y-axis rotation    
    if (lookperp.length() > 0)
    {
        look = roty * lookperp + look.parallel(yunit);
        up   = roty * up.perpendicular(yunit) + up.parallel(yunit);
    }
    
    // x & z-axis rotation 
    KMatrix transmat(up.cross(look), up, look);
    
    KVector uprotxz   = rotxz * yunit;
    KVector lookrotxz = rotxz * zunit;

    up   = transmat * uprotxz;
    look = transmat * lookrotxz;
    
    *((KMatrix*)this) = KMatrix(up.cross(look), up, look);
    
    setPosition( savePos + eye_distance * getZVector());
}
Exemplo n.º 3
0
// __________________________________________________________________________________________________
void KikiBillBoard::displayTextureWithSize ( GLuint textureId, float size )
{
    glPushAttrib (GL_TEXTURE_BIT | GL_LIGHTING_BIT);
    glDisable (GL_LIGHTING);
    glEnable (GL_TEXTURE_2D);

    glPushMatrix();

    KQuaternion quat = Controller.world->getProjection()->getQuaternion();
    KMatrix (quat).glMultMatrix();

    glBindTexture (GL_TEXTURE_2D, textureId);

    float w = size/2.0;
    float h = size/2.0;
    
    glBegin (GL_QUADS);
        glNormal3f (0,0,1);
        glTexCoord2f (0.0f, 0.0f); glVertex2f (-w, h);
        glTexCoord2f (0.0f, 1.0f); glVertex2f (-w,-h);
        glTexCoord2f (1.0f, 1.0f); glVertex2f ( w,-h);
        glTexCoord2f (1.0f, 0.0f); glVertex2f ( w, h);
    glEnd();
    
    glPopMatrix();
    
    glDisable (GL_TEXTURE_2D);
    glEnable (GL_LIGHTING);
    glPopAttrib();
}
KMatrix KMatrix::multiply(KMatrix m){
	float a = X1*m.X1 + X2*m.Y1 + X3*m.Z1;
	float b = X1*m.X2 + X2*m.Y2 + X3*m.Z2;
	float c = X1*m.X3 + X2*m.Y3 + X3*m.Z3;
	float d = Y1*m.X1 + Y2*m.Y1 + Y3*m.Z1;
	float e = Y1*m.X2 + Y2*m.Y2 + Y3*m.Z2;
	float f = Y1*m.X3 + Y2*m.Y3 + Y3*m.Z3;
	float g = Z1*m.X1 + Z2*m.Y1 + Z3*m.Z1;
	float h = Z1*m.X2 + Z2*m.Y2 + Z3*m.Z2;
	float i = Z1*m.X3 + Z2*m.Y3 + Z3*m.Z3;
	KMatrix temp = KMatrix(a,b,c,d,e,f,g,h,i);
	return temp;
}
Exemplo n.º 5
0
// __________________________________________________________________________________________________
void KikiBot::render ()
{
    float radius	= 0.5;
    float tireRadius	= 0.15;

    if (died) getDeadColor().glColor();
    else getTireColor().glColor();

    KMatrix(current_orientation).glMultMatrix();
    glPushMatrix(); // tires
    glRotated(90.0, 0.0, 1.0, 0.0);
    glTranslated(0.0, 0.0, radius-tireRadius);
    glRotated(left_tire_rot * 180.0, 0.0, 0.0, 1.0);

    render_tire;

    glPopMatrix();
    glPushMatrix();
    glRotated(90.0, 0.0, 1.0, 0.0);
    glTranslated(0.0, 0.0, -(radius-tireRadius));
    glRotated(right_tire_rot * 180.0, 0.0, 0.0, 1.0);

    render_tire;

    glPopMatrix();

    if (died == false) getBodyColor().glColor();

    render_body;

    if ((move_action || rotate_action) && died == false)
    {
        unsigned int now = Controller.getTime();
        if ((int)(now - last_fume) > Controller.mapMsTime (40))
        {
            KikiBotFume * fume = new KikiBotFume ();
            Controller.world->addObject (fume);
            fume->setPosition (current_position - getCurrentDir() * 0.4);
            last_fume = now;
        }
    }
}
KMatrix KMatrix::RotationZ(float a){
	KMatrix temp = KMatrix(cos(a), -sin(a), 0, sin(a), cos(a), 0, 0, 0, 1);
	return temp;
}
KMatrix KMatrix::RotationY(float a){
	KMatrix temp = KMatrix(cos(a), 0, sin(a), 0, 1, 0, -sin(a), 0, cos(a));
	return temp;
}
KMatrix KMatrix::RotationX(float a){
	KMatrix temp = KMatrix(1, 0, 0, 0, cos(a), -sin(a), 0, sin(a), cos(a));
	return temp;
}