示例#1
0
void rTarcom::drawHUD() {
    if (!active) return;

    //glColor4f(0,0.1,0,0.2);
    glBegin(GL_QUADS);
    glVertex3f(1, 1, 0);
    glVertex3f(0, 1, 0);
    glVertex3f(0, 0, 0);
    glVertex3f(1, 0, 0);
    glEnd();
    glPushMatrix();
    {
        glScalef(0.5, 0.5, 1);
        glTranslatef(1, 1, 0);
        glColor4f(0.8, 0.8, 0.8, 0.5);
        glBegin(GL_LINE_STRIP);
        glVertex3f(-0.7, +0.7, 0);
        glVertex3f(+0.0, +0.0, 0);
        glVertex3f(+0.7, +0.7, 0);
        glEnd();
        glColor4f(0.0, 0.4, 0.0, 0.5);
        Primitive::glDisk(16, 1.0f);
        const float r2 = 0.7;
        glColor4f(0.0, 0.6, 0.0, 0.5);
        glScalef(r2, r2, 1);
        Primitive::glDisk(16, 1.0f);
        glScalef(1.0 / r2, 1.0 / r2, 1);
        quat ori_;
        quat_cpy(ori_, ori0);
        quat_conj(ori_);
        glRotatef(90, 1, 0, 0);
        GLS::glRotateq(ori_);
        glRotatef(-90, 1, 0, 0);
        glPointSize(3);
        glBegin(GL_POINTS);
        {
            glColor4f(1, 1, 1, 1);
            glVertex3f(0, 0, 0);
        }
        glEnd();

        for(rTarget* o: *far) {
            glBegin(GL_POINTS);
            {
                glColor4f(0.5, 0.5, 0.5, 1);
                if (o->hasTag(World::getInstance()->getGroup(FAC_RED))) glColor4f(1, 0, 0, 1);
                else if (o->hasTag(World::getInstance()->getGroup(FAC_GREEN))) glColor4f(0, 1, 0, 1);
                else if (o->hasTag(World::getInstance()->getGroup(FAC_BLUE))) glColor4f(0, 0, 1, 1);
                else if (o->hasTag(World::getInstance()->getGroup(FAC_YELLOW))) glColor4f(0, 1, 0, 1);
                assert(o->object != NULL);
                if (o->object->oid == selected) glColor4f(1, 0, 1, 1);
                float dx = o->pos0[0] - pos0[0];
                float dz = o->pos0[2] - pos0[2];
                float r = sqrtf(dx * dx + dz * dz);
                dx /= r;
                dz /= r;
                float f = 0.01 * r;
                if (f < r2) {
                    glVertex3f(f * dx, -f * dz, 0);
                } else {
                    float r3 = r2 + (1.1 - r2) * log(1 + (f - r2));
                    if (r3 < 1.0) {
                        glVertex3f(r3 * dx, -r3 * dz, 0);
                    }
                }
            }
            glEnd();
        }
    }
    glPopMatrix();
}
示例#2
0
文件: pose.c 项目: pdjonov/libx42
X42_EXPORT bool X42_CALL x42_LerpAnims( x42animLerp_t *lerp,
	const x42data_t *x42, const x42animFrames_t *anim, x42opts_t *opts )
{
	uint i, j;
	
	const vec3_t * RESTRICT pv;
	const vec3_t * RESTRICT sv;
	const quat_t * RESTRICT rv;

	vec3_t * RESTRICT po;
	vec3_t * RESTRICT so;
	quat_t * RESTRICT ro;

	REF_PARAM( opts );

#ifndef LIBX42_NO_PARAM_VALIDATION
	demand_rf( lerp != NULL, X42_ERR_BADPTR, "lerp is NULL" );
	demand_rf( anim != NULL, X42_ERR_BADPTR, "anim is NULL" );
	demand_rf( x42 != NULL, X42_ERR_BADPTR, "x42 is NULL" );
	demand_rf( x42_ValidateHeader( &x42->header ), X42_ERR_BADDATA, "invalid x42 header data" );
#endif

	pv = x42->posValues;
	sv = x42->scaleValues;
	rv = x42->rotValues;

	po = lerp->p;
	so = lerp->s;
	ro = lerp->r;

	for( i = 0; i < x42->header.numAnimGroups; i++ )
	{
		const x42ksBoneEntry_t * RESTRICT p;

		uint beginBone = x42->animGroups[i].beginBone;
		uint endBone = x42->animGroups[i].endBone;

		float target = anim->frames[i].targetFrame;

		for( j = beginBone; j < endBone; j++ )
		{
			p = anim->kpairs[j][X42_KT_POSITION];

			if( p[0].value == p[1].value )
				vec3_cpy( po[j], pv[p[0].value] );
			else
			{
				float s = (float)(int)p[0].frame;
				float e = (float)(int)p[1].frame;

				float t = (target - s) / (e - s);

				vec3_lerp( po[j], pv[p[0].value], pv[p[1].value], t );
			}
		}

		for( j = beginBone; j < endBone; j++ )
		{
			p = anim->kpairs[j][X42_KT_SCALE];

			if( p[0].value == p[1].value )
				vec3_cpy( so[j], sv[p[0].value] );
			else
			{
				float s = (float)(int)p[0].frame;
				float e = (float)(int)p[1].frame;

				float t = (target - s) / (e - s);

				vec3_lerp( so[j], sv[p[0].value], sv[p[1].value], t );
			}
		}

		for( j = beginBone; j < endBone; j++ )
		{
			p = anim->kpairs[j][X42_KT_ROTATION];

			if( p[0].value == p[1].value )
				quat_cpy( ro[j], rv[p[0].value] );
			else
			{
				float s = (float)(int)p[0].frame;
				float e = (float)(int)p[1].frame;

				float t = (target - s) / (e - s);

				quat_interp( ro[j], rv[p[0].value], rv[p[1].value], t );
			}
		}
	}

	return true;
}