Esempio n. 1
0
void problem16() {
	GLubyte magenta[] = {255,0,255};
	glm::vec3 v1(100,200,1), v2(200,300,1), v3(300,200,1);
	double angle = glm::radians(45.0);

	glm::mat3 rotation(glm::cos(angle),glm::sin(angle), 0,
			      -1 * glm::sin(angle), glm::cos(angle), 0,
			      0, 0, 1);

	glm::vec3 mid(200,200,1);

	glm::mat3 trans(1,0,0,
					0,1,0,
					mid.x,mid.y,1);
	glm::mat3 oTrans(1,0,0,
					0,1,0,
					-1*mid.x,-1*mid.y,1);
	
	// translate to origin
	v1 = oTrans * v1;
	v2 = oTrans * v2;
	v3 = oTrans * v3;

	// rotation
	v1 = rotation * v1;
	v2 = rotation * v2;
	v3 = rotation * v3;

	// translate to the axis point
	v1 = trans * v1;
	v2 = trans * v2;
	v3 = trans * v3;
	
	drawTriangle(v1,v2,v3, magenta);
}
Esempio n. 2
0
void problem17() {
	GLubyte yellow[] = {200,200,0};
	glm::vec3 v1(100,200,1), v2(200,300,1), v3(300,200,1);
	double angle = glm::radians(90.0);

	glm::mat3 rotation(glm::cos(angle),glm::sin(angle), 0,
			      -1 * glm::sin(angle), glm::cos(angle), 0,
			      0, 0, 1);
	glm::vec3 mid(((v1.x + v2.x + v3.x) / 3.0), ((v1.y + v2.y + v3.y) / 3.0), 1);
	glm::mat3 trans(1,0,0,
					0,1,0,
					mid.x,mid.y,1);
	glm::mat3 oTrans(1,0,0,
					0,1,0,
					-1*mid.x,-1*mid.y,1);
	
	// trans to origin
	v1 = oTrans * v1;
	v2 = oTrans * v2;
	v3 = oTrans * v3;

	v1 = rotation * v1;
	v2 = rotation * v2;
	v3 = rotation * v3;

	v1 = trans * v1;
	v2 = trans * v2;
	v3 = trans * v3;
	
	drawTriangle(v1,v2,v3, yellow);
}
Esempio n. 3
0
void CGmObjCockpit::Proc()
{
	const TVec oDir(
		//m_poPlayer_->m_oCamDir
		m_poPlayer_->GetCamDirAvg()
		);
	const TVec oPos( 
		//m_poPlayer_->GetPos()
		m_poPlayer_->GetCamPos()
		);
	const float fSpeedAvg( m_poPlayer_->GetSpeedAvg() );
	//const float fSpeedMax( m_poPlayer_->GetSpeedMax() );
	//const float fSpeedProg( fSpeedAvg / ( fSpeedMax ) );
	const float fCamRotHorzAvg( m_poPlayer_->GetCamRotHorzAvg() );
	const float fEnergy( m_poPlayer_->GetEnergy() );
	const int iLives( m_poPlayer_->GetLives_() );
	const unsigned int uiWeaponCount( m_poPlayer_->GetWeaponCount() );
	const int iWeaponIndexCurr( m_poPlayer_->GetWeaponIndexCurr() );
	const unsigned int uiStrikeCount( m_poPlayer_->GetStrikeCount() );
	const int iWeaponAmmo( m_poPlayer_->GetWeaponAmmo() );
	
	TVec oDirNorm( oDir );
	oDirNorm.Normalize();
	//TVec oVel( m_poBody->GetVelocity() );
	//oVel.Normalize();
	const TVec oSpeedOffset( 
		- oDirNorm * 0.005f * fSpeedAvg );// * oVel.Dot( oDir );
	//m_poMeshCockpit->m_oTrans = (
	TVec oTrans(
		oPos
		+ oSpeedOffset
		);
	
	// tmp
	glPushAttrib( GL_ENABLE_BIT | GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_COLOR_BUFFER_BIT );
	glEnable( GL_LIGHTING );
	glDisable( GL_COLOR_MATERIAL );
	//glDisable( GL_LIGHTING );
	//glEnable( GL_COLOR_MATERIAL );
	glEnable( GL_CULL_FACE );
	glEnable( GL_TEXTURE_2D );
	
	// tmp
	//m_poResMan_->UpdateAllLights();
	//glEnable( GL_LIGHT0 );
	
	CMatrix4x4 oMat;
	oMat.Orient( -oDir );
	oMat.Translate( oTrans );
	glPushMatrix();
	glMultMatrixf( oMat );
	glRotatef( RAD_TO_DEG( fCamRotHorzAvg ), 0.0f, 0.0f, 1.0f );
	
	m_poResMan_->EnableAllLights( false );
	CGLight oLight0( 0,
		CG::TVec(0.0000f, 1.0000f, 2.0000f, 0.0000f),	// Position. Std: (0.0f, 0.0f, 1.0f, 0.0f)
		CG::TVec(0.0000f, 0.0000f, 0.0000f, 1.0000f),	// Ambient.  Std: (0.0f, 0.0f, 0.0f, 1.0f)
		CG::TVec(0.3000f, 0.4000f, 0.5000f, 1.0000f),	// Diffuse.  Std: (1.0f, 1.0f, 1.0f, 1.0f)
		CG::TVec(1.0000f, 1.0000f, 1.0000f, 1.0000f),	// Specular. Std: (1.0f, 1.0f, 1.0f, 1.0f)
		CG::TVec(0.0000f, 0.0000f,-1.0000f, 0.0000f),	// Direction. Std: (0.0f, 0.0f, -1.0f, 1.0f)
		0.0000f,					// SpotExponent, [0.0f, 128.0f], Std: 0.0f.
		180.00f,					// SpotCutoff, [0.0f, 90.0f], 180.0f, Std: 180.0f.
		1.0000f,					// ConstantAttenuation,	Std: 1.0f.
		0.0000f,					// LinearAttenuation,	Std: 0.0f.
		0.0000f 					// QuadraticAttenuation	Std: 0.0f.
		);
	
	oLight0.m_oPos.Set( 1.0f, 4.0f, 5.0f );
	oLight0.Update();
	oLight0.On();
	
	if( m_poMeshCockpit )
	{
		//m_poMeshCockpit->m_oColor.Set( 1.0f, 1.0f, 1.0f, m_fEnergy );
		//m_poMeshCockpit->m_oOrient.OrientYZ( oUp, oDir );
		//m_poMeshCockpit->m_oOrient.Orient( -oDir );
		m_poMeshCockpit->Render();
	}
	unsigned int i;

	const unsigned int uiMeshCount0( m_oArrMeshInterface0.GetSize() );
	const unsigned int uiMeshCount1( m_oArrMeshInterface1.GetSize() );
	const unsigned int uiMeshCount2( m_oArrMeshInterface2.GetSize() );
	
	i = MIN( (unsigned int)( iLives ), uiMeshCount0 );
	while( i )
	{
		--i;
		m_oArrMeshInterface0[i]->Render();
	}
	i = MIN( (unsigned int)( uiWeaponCount ), uiMeshCount1 );
	while( i )
	{
		--i;
		if( m_poPlayer_->IsWeaponUnlocked( i ) )
			m_oArrMeshInterface1[i]->Render();
	}
	if( iWeaponIndexCurr >= 0 && iWeaponIndexCurr < int( uiMeshCount1 ) )
	{
		glEnable( GL_COLOR_LOGIC_OP );
		glLogicOp( GL_INVERT );
		m_oArrMeshInterface1[iWeaponIndexCurr]->Render();
		glDisable( GL_COLOR_LOGIC_OP );
	}
	i = uiMeshCount2;
	while( i )
	{
		--i;
		m_oArrMeshInterface2[i]->Render();
	}
	glEnable( GL_COLOR_LOGIC_OP );
	glLogicOp( GL_INVERT );
	i = uiMeshCount2;
	while( i )
	{
		--i;
		if( uiStrikeCount & ( 1 << i ) )
			m_oArrMeshInterface2[i]->Render();
	}
	glDisable( GL_COLOR_LOGIC_OP );
	
	// Inventar.
	i = m_uiInventarIdx;
	while( i )
	{
		--i;
		m_oArrInventar[i].Render();
	}
	
	glDisable( GL_LIGHTING );
	glEnable( GL_COLOR_MATERIAL );
	glEnable( GL_COLOR_LOGIC_OP );
	glLogicOp( GL_INVERT );
	glEnable( GL_ALPHA_TEST );
	glAlphaFunc( GL_GREATER, 0.1f );

	// tmp
	// energy display
	{
		const TVec oD( m_oDisplayEnergyDiff * 0.5f * fEnergy );
		const TVec oP0( m_oDisplayEnergyMid - oD );
		const TVec oP1( m_oDisplayEnergyMid + oD );
		const TVec oUp( 0.0f, 0.08f, 0.0f );
		const float fT( m_fT_ * 3.0f );
		float fTX( fEnergy * 10.0f );
		if( m_poTexDisplayEnergy )
			m_poTexDisplayEnergy->Bind();
		
		glBegin( GL_QUADS );
		glColor4f( 0.5f, 1.0f, 1.0f, 0.5f );
		glTexCoord2f( -fTX + fT, 0.0f );
		glVertex3fv( oP0 - oUp );
		glTexCoord2f( +fTX + fT, 0.0f );
		glVertex3fv( oP1 - oUp );
		glTexCoord2f( +fTX + fT, 1.0f );
		glVertex3fv( oP1 + oUp );
		glTexCoord2f( -fTX + fT, 1.0f );
		glVertex3fv( oP0 + oUp );
		glEnd();
		
		/*
		// tmp
		glDisable( GL_ALPHA_TEST );
		glDisable( GL_COLOR_LOGIC_OP );
		glBlendFunc( GL_ONE, GL_ONE );
		
		glBegin( GL_QUADS );
		glColor4f( 0.5f, 1.0f, 1.0f, 0.8f );
		glTexCoord2f( -fTX + m_fT_, 0.0f );
		glVertex3fv( oP0 - oUp );
		glTexCoord2f( +fTX + m_fT_, 0.0f );
		glVertex3fv( oP1 - oUp );
		glTexCoord2f( +fTX + m_fT_, 1.0f );
		glVertex3fv( oP1 + oUp );
		glTexCoord2f( -fTX + m_fT_, 1.0f );
		glVertex3fv( oP0 + oUp );
		glEnd();
		*/
		if( m_poTexDisplayEnergy )
			m_poTexDisplayEnergy->Unbind();
	}
	
	// tmp
	// tilt vert display
	const float fTilt( oDir[1] );
	if( fTilt )
	{
		const float fExt( 0.04f );
		const TVec oVertDiff( m_oDisplayTiltVertDiff * fTilt );
		const TVec oVertP0( m_oDisplayTiltVertMid );
		const TVec oVertP1( m_oDisplayTiltVertMid + oVertDiff * 0.5f );
		const TVec oVertUp( ( fTilt > 0.0f ? -fExt : +fExt ), 0.0f, 0.0f ); //( TVec( 0.0f, 0.0f, 1.0f ) * oVertDiff.Normalized() ) * fExt );
		
		if( m_poTexDisplayTilt )
			m_poTexDisplayTilt->Bind();
		glBegin( GL_QUADS );
		glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
		glTexCoord2f( 0.0f, 0.0f );
		glVertex3fv( oVertP0 - oVertUp );
		glTexCoord2f( 1.0f, 0.0f );
		glVertex3fv( oVertP1 - oVertUp );
		glTexCoord2f( 1.0f, 1.0f );
		glVertex3fv( oVertP1 + oVertUp );
		glTexCoord2f( 0.0f, 1.0f );
		glVertex3fv( oVertP0 + oVertUp );
		glEnd();
		if( m_poTexDisplayTilt )
			m_poTexDisplayTilt->Unbind();
	}
	
	// toopt
	// ammo display
	if( iWeaponAmmo >= 0 && m_oTexTxt_.m_poTex )
	{
		const float fStp( 1.0f );
		int iAmmo( iWeaponAmmo );
		//float fX1( 0.0f );
		const float fScale( 0.2f );
		const TVec oStpLeft( m_oDisplayAmmoLeftDir * fScale );
		const TVec oStpUp( m_oDisplayAmmoUpDir * fScale );
		TVec oPosRef( m_oDisplayAmmoLeftPos0 );
		unsigned int uiDigit( 0 );
		m_oTexTxt_.m_poTex->Bind();
		do
		{
			const int iNum( iAmmo % 10 );
			iAmmo /= 10;
			
			float fTX0, fTY0, fTW, fTH;
			m_oTexTxt_.GetCharTexCoord( '0' + iNum, &fTX0, &fTY0, &fTW, &fTH );
			const float fTX1( fTX0 + fTW );
			const float fTY1( fTY0 + fTH );
			
			const float fWidth( fTW * ( fStp / fTH ) );
			
			const TVec oW( oStpLeft * fWidth );
			const TVec oP0( oPosRef + oW );
			const TVec oP1( oPosRef );
			const TVec oP2( oPosRef + oStpUp );
			const TVec oP3( oPosRef + oW + oStpUp );
			
			glBegin( GL_QUADS );
			glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
			glTexCoord2f( fTX0, fTY0 );
			glVertex3fv( oP0 );
			glTexCoord2f( fTX1, fTY0 );
			glVertex3fv( oP1 );
			glTexCoord2f( fTX1, fTY1 );
			glVertex3fv( oP2 );
			glTexCoord2f( fTX0, fTY1 );
			glVertex3fv( oP3 );
			glEnd();
			
			oPosRef += oStpLeft;
			
			/*
			const float fX0( fX1 - fWidth );
			glBegin( GL_QUADS );
			glColor4f( 1.0f, 1.0f, 1.0f, 0.5f );
			glTexCoord2f( fTX0, fTY0 );
			glVertex3f( fX0, 0.0f, -5.0f );
			glTexCoord2f( fTX1, fTY0 );
			glVertex3f( fX1, 0.0f, -5.0f );
			glTexCoord2f( fTX1, fTY1 );
			glVertex3f( fX1, fStp, -5.0f );
			glTexCoord2f( fTX0, fTY1 );
			glVertex3f( fX0, fStp, -5.0f );
			glEnd();

			fX1 -= fWidth;
			*/
		}
		while( iAmmo > 0 );
		m_oTexTxt_.m_poTex->Unbind();
	}
	else
	{
		// todo
	}
	
	glPopMatrix();
	glPopAttrib();
}