Ejemplo n.º 1
0
void nebu_Camera_Roll(nebu_Camera *pCamera, float d) {
    vec3 v;
    matrix m;
    vec3_Sub(&v, &pCamera->vLookAt, &pCamera->vEye);
    vec3_Normalize(&v, &v);
    matrixRotationAxis(&m, d * 2 * (float)M_PI / 360.0f, &v);
    vec3_Transform(&pCamera->vUp, &pCamera->vUp, &m);
}
Ejemplo n.º 2
0
void Cylinder::logic(int dt)
{
	m_time += dt;
	float angle = m_time * ROTATE_SPEED;

	D3DXMatrixIdentity(&m_bones[1]);	
	matrixRotationAxis(&m_bones[1], CYLINDER_AXIS, angle);
	D3DXMatrixTranspose(&m_bones[1], &m_bones[1]);
	
	if(angle >= MAX_ANGLE)
	{
		m_time = 0;
	}
}
Ejemplo n.º 3
0
void Engine::proccessLogic(unsigned int dt)
{
	m_time += dt;
	float angle = m_time * ROTATE_SPEED;

	D3DXMatrixIdentity(&m_bones[1]);	
	matrixRotationAxis(&m_bones[1], CYLINDER_AXIS, angle);
	D3DXMatrixTranspose(&m_bones[1], &m_bones[1]);
	
	if(angle >= MAX_ANGLE)
	{
		m_time = 0;
	}
	if(FAILED(m_d3dDevice->SetVertexShaderConstantF(8, &(m_bones[1].m[0][0]), 4)))
	{
		stop();
	}
}
Ejemplo n.º 4
0
void nebu_Camera_Rotate(nebu_Camera *pCamera, int flags,
                        float dx, float dy)
{
    // adjust up vector, so that it is orthogonal to
    // view direction
    vec3 vDiff, vView, vRight, vUp;
    vec3 vdx, vdy;
    vec3 *pvCenter, *pvMoving;

    switch(flags & NEBU_CAMERA_ROTATE_MASK)
    {
    case NEBU_CAMERA_ROTATE_AROUND_EYE:
        pvCenter = &pCamera->vEye;
        pvMoving = &pCamera->vLookAt;
        break;
    case NEBU_CAMERA_ROTATE_AROUND_LOOKAT:
        pvCenter = &pCamera->vLookAt;
        pvMoving = &pCamera->vEye;
        break;
    default:
        assert(0);
        return;
    }

    vec3_Sub(&vDiff, pvCenter, pvMoving);
    vec3_Normalize(&vView, &vDiff);
    vec3_Cross(&vRight, &pCamera->vUp, &vView);
    vec3_Normalize(&vRight, &vRight);
    vec3_Cross(&vUp, &vView, &vRight);
    vec3_Normalize(&vUp, &vUp);

    // horizontal movement (dx):
    if(dx == 0) {
        vec3_Zero(&vdx);
    } else {
        // rotate moving around up vector through center point
        vec3 v = vDiff;
        float fAngle = dx * 2 * (float)M_PI / 360.0f;
        matrix matRotation;
        matrixRotationAxis(&matRotation, fAngle, &vUp);
        vec3_Transform(&v, &vDiff, &matRotation);
        vec3_Sub(&vdx, &v, &vDiff);
    }

    // vertical movement (dy):
    if(dy == 0) {
        vec3_Zero(&vdy);
    } else {
        // rotate eye point around up vector through lookAt point
        vec3 v = vDiff;
        float fAngle = dy * 2 * (float)M_PI / 360.0f;
        matrix matRotation;
        matrixRotationAxis(&matRotation, fAngle, &vRight);
        vec3_Transform(&v, &vDiff, &matRotation);
        vec3_Sub(&vdy, &v, &vDiff);

        matrixTranspose(&matRotation, &matRotation);
        if(!(flags & NEBU_CAMERA_FIXED_UP))
            vec3_Transform(&pCamera->vUp, &pCamera->vUp, &matRotation);
    }

    {
        vec3 v;
        vec3_Add(&v, &vdx, &vdy);
        vec3_Add(&v, &v, pvMoving);
        vec3_Sub(&v, &v, pvCenter);
        vec3_Normalize(&v, &v);
        // printf("up dot view: %.4f\n", - vec3_Dot(&v, &pCamera->vUp));
        vec3_Scale(&v, &v, vec3_Length(&vDiff));
        vec3_Add(pvMoving, &v, pvCenter);

    }
}
Ejemplo n.º 5
0
void drawCam(int player) {
	int i;
	float up[3] = { 0, 0, 1 };
	Visual *d = & gPlayerVisuals[player].display;
	
	float reflectivity = getReflectivity();
	// compute shadow color based on glocal constant & reflectivity
	for(i = 0; i < 4; i++) 
		gCurrentShadowColor[i] = gShadowColor[i] * (1 - reflectivity);

	glColor3f(0.0, 1.0, 0.0);

	glMatrixMode(GL_PROJECTION);
	glLoadIdentity();
	doPerspective(gSettingsCache.fov, (float) d->vp_w / (float) d->vp_h,
		gSettingsCache.znear, box2_Diameter(& game2->level->boundingBox) * 6.5f);

	glMatrixMode(GL_MODELVIEW);
	glLoadIdentity();

	{
		vec3 vLookAt;
		vec3 vTarget;
		matrix matRotate;

		vec3_Sub(&vLookAt, (vec3*)gPlayerVisuals[player].camera.target, (vec3*)gPlayerVisuals[player].camera.cam);
		vec3_Normalize(&vLookAt, &vLookAt);
		matrixRotationAxis(&matRotate, 90.0f * (float) gPlayerVisuals[player].camera.bIsGlancing, (vec3*)up);
		vec3_Transform(&vLookAt, &vLookAt, &matRotate);
		vec3_Add(&vTarget, (vec3*)gPlayerVisuals[player].camera.cam, &vLookAt);
		doLookAt(gPlayerVisuals[player].camera.cam, (float*)&vTarget, up);
	}

	glDisable(GL_LIGHTING); // initial config at frame start
	glDisable(GL_BLEND); // initial config at frame start

	// disable writes to alpha
	glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

	/* skybox */
	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);

	drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	/* skybox done */

	/* floor */ 
	if(reflectivity == 0) {
		// draw floor to fb and stencil (set to 1),
		// using alpha-blending
		// TODO: draw floor alpha to fb
		video_Shader_Setup(& gWorld->floor_shader);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glStencilFunc(GL_ALWAYS, 1, 255);
		glEnable(GL_STENCIL_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
		nebu_Mesh_DrawGeometry( gWorld->floor );
		glDisable(GL_BLEND);
		glDisable(GL_STENCIL_TEST);
		video_Shader_Cleanup(& gWorld->floor_shader);
	} else {
		/* reflections */
		/* first draw reflector to stencil */
		/* and reflector alpha to fb */

		video_Shader_Setup(& gWorld->floor_shader);

		// store only reflector alpha in framebuffer
		glDepthMask(GL_FALSE);
		glStencilOp(GL_KEEP, GL_KEEP, GL_REPLACE);
		glStencilFunc(GL_ALWAYS, 1, 255);
		glEnable(GL_STENCIL_TEST);
		glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_TRUE);
		// glEnable(GL_ALPHA_TEST);
		// glAlphaFunc(GL_GREATER, 0.1f);

		nebu_Mesh_DrawGeometry( gWorld->floor );
		
		// glDisable(GL_ALPHA_TEST);
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE);
		glDepthMask(GL_TRUE);
		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		glStencilFunc(GL_EQUAL, 1, 255);

		video_Shader_Cleanup(& gWorld->floor_shader);
		
		/* then draw world & skybox reflected, where stencil is set */
		/* protect the alpha buffer */
		glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_FALSE);

		isRenderingReflection = 1; // hack: reverse lighting
		glPushMatrix();
		glScalef(1,1,-1);
		glCullFace(GL_FRONT); // reverse culling
		// clip skybox & world to floor plane
		glEnable(GL_CLIP_PLANE0);
		{
			double plane[] = { 0, 0, 1, 0 };
			glClipPlane(GL_CLIP_PLANE0, plane);
		}

		drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );
		drawWorld(player);

		glDisable(GL_CLIP_PLANE0);
		glCullFace(GL_BACK);
		glPopMatrix();
		isRenderingReflection = 0; // hack: normal lighting

		/* then blend the skybox into the scene, where stencil is set */
		/* modulate with the destination alpha */
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_ONE_MINUS_DST_ALPHA, GL_DST_ALPHA);
		drawSkybox( box2_Diameter( & game2->level->boundingBox ) * 2.5f );
		glDisable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
		
		/* then blend reflector into the scene */
		glDisable(GL_DEPTH_TEST);
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		glColor4f(1, 1, 1, 1 - reflectivity);

		glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP);
		glStencilFunc(GL_ALWAYS, 1, 255);

		video_Shader_Setup(& gWorld->floor_shader);
		nebu_Mesh_DrawGeometry( gWorld->floor );
		video_Shader_Cleanup(& gWorld->floor_shader);

		glDisable(GL_STENCIL_TEST);
		glDisable(GL_BLEND);
		glEnable(GL_DEPTH_TEST);
	}
	/* floor done */

	/* planar shadows */
	glDepthMask(GL_FALSE);
	glDisable(GL_DEPTH_TEST);

	if(reflectivity != 1) // there are no shadows on perfect mirrors
		drawPlanarShadows(player);

	glDepthMask(GL_TRUE);
	glEnable(GL_DEPTH_TEST);
	/* planar shadows done */

	drawWorld(player);

	/* transparent stuff */
	/* draw the glow around the other players: */
	if (gSettingsCache.show_glow == 1) {
		glEnable(GL_BLEND);
		glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

		for (i = 0; i < game->players; i++)
		{
			if (i != player && PLAYER_IS_ACTIVE(game->player + i))
			{
				drawGlow(&gPlayerVisuals[player].camera, game->player + i, gPlayerVisuals + i,
					d, TRAIL_HEIGHT * 4);
			}
		}
		glDisable(GL_BLEND);
	}
}
Ejemplo n.º 6
0
void nebu_Camera_RotateAroundTarget(nebu_Camera *pCamera,
																		float dx, float dy) {
	// adjust up vector, so that it is orthogonal to
	// view direction
	vec3 vDiff, vView, vRight, vUp;
	vec3 vdx, vdy;
	
	vec3_Sub(&vDiff, &pCamera->vLookAt, &pCamera->vEye);
	vec3_Normalize(&vView, &vDiff);
	vec3_Cross(&vRight, &pCamera->vUp, &vView);
	vec3_Normalize(&vRight, &vRight);
	vec3_Cross(&vUp, &vView, &vRight);
	vec3_Normalize(&vUp, &vUp);
	
	// horizontal movement (dx):
	if(dx == 0) {
		vec3_Zero(&vdx);
	} else {
		// rotate eye point around up vector through lookAt point
		vec3 v = vDiff;
		float fAngle = dx * 2 * M_PI / 360.0;
		matrix matRotation;
		matrixRotationAxis(&matRotation, fAngle, &vUp);
		vec3_Transform(&v, &vDiff, &matRotation);
		vec3_Sub(&vdx, &v, &vDiff);
	}

	// vertical movement (dy):
	if(dy == 0) {
		vec3_Zero(&vdy);
	} else {
		// rotate eye point around up vector through lookAt point
		vec3 v = vDiff;
		float fAngle = dy * 2 * M_PI / 360.0;
		matrix matRotation;
		matrixRotationAxis(&matRotation, fAngle, &vRight);
		vec3_Transform(&v, &vDiff, &matRotation);
		vec3_Sub(&vdy, &v, &vDiff);

		matrixTranspose(&matRotation, &matRotation);
		vec3_Transform(&pCamera->vUp, &pCamera->vUp, &matRotation);
	}

	// add relative movements to camera position
	
	/*
	vec3_Add(&pCamera->vEye, &pCamera->vEye, &vdx);
	vec3_Add(&pCamera->vEye, &pCamera->vEye, &vdy);
	*/
	{
		vec3 v;
		vec3_Add(&v, &vdx, &vdy);
		vec3_Add(&v, &v, &pCamera->vEye);
		vec3_Sub(&v, &v, &pCamera->vLookAt);
		vec3_Normalize(&v, &v);
		// printf("up dot view: %.4f\n", - vec3_Dot(&v, &pCamera->vUp));
		vec3_Scale(&v, &v, vec3_Length(&vDiff));
		vec3_Add(&pCamera->vEye, &v, &pCamera->vLookAt);

	}
}