Beispiel #1
0
void Motion(void)
{
    rot += 3.0f;
    if (rot >= 360.0f) rot -= 360.0f;
    UpdateModelView();
    Redraw();
}
Beispiel #2
0
/* ARGSUSED1 */
void Button(int button, int state, int x, int y)
{
    switch (button) {
    case GLUT_LEFT_BUTTON:
        if (state == GLUT_DOWN) {
            rot -= 15.0f;
            UpdateModelView();
            Redraw();
        }
        break;
    case GLUT_RIGHT_BUTTON:
        if (state == GLUT_DOWN) {
            rot += 15.0f;
            UpdateModelView();
            Redraw();
        }
        break;
    }
}
Beispiel #3
0
void InitMatrices(void)
{
    /* Calculate projection matrix */
    glMatrixMode(GL_PROJECTION);
    glPushMatrix();
    glLoadIdentity();
    gluPerspective(45.0f, 1.0f, 1.0f, 100.0f);
    /* Retrieve the matrix */
    glGetFloatv(GL_PROJECTION_MATRIX, Projection);
    glPopMatrix();
    glMatrixMode(GL_MODELVIEW);

    UpdateModelView();
}
Beispiel #4
0
bool Shadows::Render()
{
	/* Input - timer and fps graph */
	timer.Update();

	float dt = timer.GetDeltaTime();

	pFPSGraph->Input(1.0f / dt, timer.GetTime());


	/* User input */
	if (KeyPressed(KEY_SPACE))
	{
		iCurrentGroup = (iCurrentGroup + 1) % (int)GROUPS_COUNT;
	}
	if (KeyPressed(KEY_ENTER))
	{
		eDisplayMode = (eDisplayMode + 1) % E_DISPLAY_MODES;
	}
	if (KeyPressing(KEY_LEFT))
	{
		if ((fShadowExtent -= dt * 300.0f) < fMinShadowExtent)
			fShadowExtent = fMinShadowExtent;
	}
	if (KeyPressing(KEY_RIGHT))
	{
		if ((fShadowExtent += dt * 300.0f) > fMaxShadowExtent)
			fShadowExtent = fMaxShadowExtent;
	}
	if (KeyPressed(KEY_8))
	{
		bUseDoubleStencil = !bUseDoubleStencil;
	}
	if (KeyPressed(KEY_9))
	{
		bLightMove = !bLightMove;
	}
	if (KeyPressed(KEY_0))
	{
		bWireframe = !bWireframe;
	}
	if (KeyPressing(KEY_UP))
	{
		if ((fDistance -= dt * 150.0f) < fMinDistance)
			fDistance = fMinDistance;
	}
	if (KeyPressing(KEY_DOWN))
	{
		if ((fDistance += dt * 150.0f) > fMaxDistance)
			fDistance = fMaxDistance;
	}
	if (ScrollUp())
	{
		if ((fDistance /= 1.05f) < fMinDistance)
			fDistance = fMinDistance;
	}
	if (ScrollDown())
	{
		if ((fDistance *= 1.05f) > fMaxDistance)
			fDistance = fMaxDistance;
	}
	if (KeyPressed(KEY_R))
	{
		bFPSMode = !bFPSMode;
	}

	if (bFPSMode)
	{
		fpsCamera.Update(this, dt);
	}
	else
	{

		if (KeyPressing(KEY_Q))
		{
			light[iCurLight].fLightHeight += 50.0f * dt;
		}
		if (KeyPressing(KEY_E))
		{
			light[iCurLight].fLightHeight -= 50.0f * dt;
		}
		if (KeyPressing(KEY_W))
		{
			light[iCurLight].fLightRadius += dt;
		}
		if (KeyPressing(KEY_S))
		{
			light[iCurLight].fLightRadius -= dt;
		}
	}
	if (KeyPressed(KEY_1))
	{
		if (iNumLights > 1)
			iNumLights--;
	}
	if (KeyPressed(KEY_2))
	{
		if (iNumLights < MAX_LIGHTS)
			iNumLights++;
	}

	
	// Update light positions
	if (bLightMove)
	{
		for (unsigned int i = 0; i < MAX_LIGHTS; i++)
		{
			light[i].fLightAngle += dt;

			light[i].UpdatePos(fMinDistance);
		}
	}

	/* Update camera state */
	y += 0.002f * (GetPointer()->GetMotionX() + GetPointer()->GetInertiaX());
	x -= 0.002f * (GetPointer()->GetMotionY() + GetPointer()->GetInertiaY());
	if (GetPointer()->TimeSinceLastInput() > 10.0f && bLightMove)
		t += dt;

	yRot = y + 20.0f * t;
	xRot = x + 20.0f * sin(t);

	/* Rendering */
	// Clear color and depth buffer
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	glEnable(GL_DEPTH_TEST);

	UpdateModelView();


	glEnable(GL_CULL_FACE);

	// Draw scene (including shadow if enabled)
	RenderScene();

	glDisable(GL_CULL_FACE);

	// Render Light
	for (unsigned int i = 0; i < iNumLights; i++)
	{
		DrawLightMarker(light[i].fPos);
	}

	//glDisable(GL_DEPTH_TEST);
	glClear(GL_DEPTH_BUFFER_BIT);

	DrawCoordinateFrame();

	if (iShowInfo)
	{
		pFPSGraph->Draw();

		glEnable(GL_BLEND);
		pFont->Bind();

		pFPSGraph->TextDraw(pFont.get());

		// font parameters
		float yellow[] = {1.0,1.0,0.0,1.0};
		float red[] = {1.0,0.0,0.0,1.0};
		float scale = 0.06f;
		float mscale = 0.07f;
		float x = -1.0f;
		float y = 1.0f;

		FontManager::HorzAlign horz = FontManager::LeftAlign;
		FontManager::VertAlign vert = FontManager::TopAlign;

		if (iShowInfo >= 2)
		{
			pFont->Render(x, y -= mscale, scale, red, horz, vert,
				"[LEFT,RIGHT] Extent=%.1f", fShadowExtent);

			char text[200];
			CurrentGroupDesc(text);

			pFont->Render(x, y -= mscale, scale, red, horz, vert,
				text);

			pFont->Render(x, y -= mscale, scale, red, horz, vert,
				"[ENTER] Render Mode=%s", DisplayMoreStr[eDisplayMode]);

			pFont->Render(x, y -= mscale, scale, red, horz, vert,
				"[8] Double Stencil=%d", bUseDoubleStencil ? 1 : 0);

			pFont->Render(x, y -= mscale, scale, red, horz, vert,
				"[0] Wireframe=%d", bWireframe ? 1 : 0);

		}

		glDisable(GL_BLEND);
	}
	iFrameCounter++;
	
	return true;
}