Example #1
0
void applyCameraState(camera_struct* c, cameraState_struct* cs)
{
	if(!c || !cs)return;

	c->position=cs->position;
	c->viewPosition=cs->position;

	initTransformationMatrix(c);
	rotateMatrixX(c->transformationMatrix, cs->angle.x, false);
	rotateMatrixY(c->transformationMatrix, cs->angle.y, false);
	rotateMatrixZ(c->transformationMatrix, cs->angle.z, false);

	// NOGBA("p : %d %d %d",cs->position.x,cs->position.y,cs->position.z);
	// NOGBA("a : %d %d %d",cs->angle.x,cs->angle.y,cs->angle.z);
}
Example #2
0
void updatePlayer(player_s* p, room_s* r)
{
	if(!p)return;

	md2InstanceUpdate(&p->gunInstance);
	md2InstanceUpdate(&p->ratmanInstance);
	if(!p->flying) p->object.speed = vaddf(p->object.speed, vmulf(normGravityVector, 0.04f));
	vect3Df_s prevPosition = p->object.position;
	collideObjectRoom(&p->object, r);

	if(p->inPortal && !p->oldInPortal)playSFX(portalEnterSFX[rand()%2]);
	else if(!p->inPortal && p->oldInPortal)playSFX(portalExitSFX[rand()%2]);

	int i;
	for(i=0; i < NUM_PORTALS; i++)
	{
		if(portals[i].target)checkPortalPlayerWarp(p, &portals[i]);
	}

	updateCamera(&p->camera);

	float alignment = -vdotf(vect3Df(p->camera.orientation[0][0],p->camera.orientation[0][1],p->camera.orientation[0][2]), normGravityVector);
	// printf("alignment : %f  \n",alignment);

	{
		if(alignment>0.001)
		{
			if(alignment>0.125)rotateMatrixZ((float*)p->camera.orientation, -0.5f*0.15f, true);
			else if(alignment>0.0625)rotateMatrixZ((float*)p->camera.orientation, -0.25f*0.15f, true);
			else if(alignment>0.03125)rotateMatrixZ((float*)p->camera.orientation, -0.125f*0.07f, true);
		}else if(alignment<-0.001)
		{
			if(alignment<-0.125)rotateMatrixZ((float*)p->camera.orientation, 0.5f*0.15f, true);
			else if(alignment<-0.0625)rotateMatrixZ((float*)p->camera.orientation, 0.25f*0.15f, true);
			else if(alignment<-0.03125)rotateMatrixZ((float*)p->camera.orientation, 0.125f*0.07f, true);
		}
	}
	
	// fixMatrix(c->orientation); //compensate floating point errors

	p->camera.position = vaddf(p->object.position, vect3Df(0.0f, cos(p->walkCnt1)*0.14f, 0.0f));

	if(vmagf(p->object.speed) < 0.03f || !p->object.contact)md2InstanceChangeAnimation(&p->ratmanInstance, 0, false);

	if(p->flying) p->object.speed = vect3Df(0,0,0); //TEMP
	p->tempAngle = vmulf(p->tempAngle, 0.65f);
}
Example #3
0
File: main.c Project: minexew/ctrgl
static void set3DView()
{
    static const float nearZ = 0.01f, farZ = 100.0f;
    mtx44 projection, modelView;

    // standard perspective projection
    initProjectionMatrix((float*) projection, 80.0f*M_PI/180.0f, 240.0f/400.0f, nearZ, farZ);
    rotateMatrixZ((float*) projection, M_PI/2, false);   //because framebuffer is sideways...
    glPerspectiveProjectionMatrixfCTR((float*) projection,
            nearZ,  // must match the value passed to initProjectionMatrix

            -5.0f,  // depth of the plane that will converge at screen depth in stereo,
                    // e.g. everything further will be behind the screen, everything closer will pop out

            0.2f    // determine experimentally; allows you to mix multiple views in one coherent stereo
            );

    // poor man's camera control
    loadIdentity44((float*) modelView);
    translateMatrix((float*) modelView, position.x, position.y, position.z);
    rotateMatrixX((float*) modelView, angle.x, false);
    rotateMatrixY((float*) modelView, angle.y, false);
    glModelviewMatrixfCTR((float*) modelView);
}