Beispiel #1
0
void Mesh::GenerateTangents () {
	if (! textureCoords ) {
		return;
	}
	if (! tangents ) {
		tangents = new Vector3 [ numVertices ];
	}
	for ( GLuint i = 0; i < numVertices ; ++i){
		tangents [i] = Vector3 ();
	}
	if( indices ) {
		for ( GLuint i = 0; i < numIndices ; i +=3){
			int a = indices [i];
			int b = indices [i +1];
			int c = indices [i +2];

			Vector3 tangent = GenerateTangent ( vertices [a], vertices [b],
			vertices [c], textureCoords [a],
			textureCoords [b], textureCoords [c]);

			tangents [a] += tangent ;
			tangents [b] += tangent ;
			tangents [c] += tangent ;
		}
	}
	else {
		for ( GLuint i = 0; i < numVertices ; i +=3){
			Vector3 tangent = GenerateTangent ( vertices [i], vertices [i+1] ,
			vertices [i+2] , textureCoords [i],
			textureCoords [i+1] , textureCoords [i+2]);

			tangents [i] += tangent ;
			tangents [i+1] += tangent ;
			tangents [i+2] += tangent ;
		}
	}
	for ( GLuint i = 0; i < numVertices ; ++i){
		tangents [i]. Normalise ();
	}
}
Beispiel #2
0
void Mesh::GenerateTangents(){
	if (!m_Tangents) {
		m_Tangents = new Vector3[m_NumVertices];
	}
	for (GLuint i = 0; i < m_NumVertices; ++i){
		m_Tangents[i] = Vector3();
	}
	if (!m_TextureCoords) {
		return;
	}
	if (m_Indices) {
		for (GLuint i = 0; i < m_NumIndices; i += 3){
			unsigned int a = m_Indices[i];
			unsigned int b = m_Indices[i + 1];
			unsigned int c = m_Indices[i + 2];

			Vector3 tangent = GenerateTangent(m_Vertices[a], m_Vertices[b], m_Vertices[c], m_TextureCoords[a], m_TextureCoords[b], m_TextureCoords[c]);
			m_Tangents[a] += tangent;
			m_Tangents[b] += tangent;
			m_Tangents[c] += tangent;
		}
	}

	else{
		for (GLuint i = 0; i < m_NumVertices; i += 3){
			Vector3 tangent = GenerateTangent(m_Vertices[i], m_Vertices[i + 1],
				m_Vertices[i + 2], m_TextureCoords[i],
				m_TextureCoords[i + 1], m_TextureCoords[i + 2]);

			m_Tangents[i] = tangent;
			m_Tangents[i + 1] = tangent;
			m_Tangents[i + 2] = tangent;
		}
	}
	for (GLuint i = 0; i < m_NumVertices; ++i){
		m_Tangents[i].Normalise();
	}
}
Beispiel #3
0
bool AICmdFlyAround::TimeStepUpdate()
{
	if (m_targmode == 1 && !m_target) return true;
	if (!ProcessChild()) return false;

	// Not necessary unless it's a tier 1 AI
	if (m_ship->GetFlightState() == Ship::FLYING) m_ship->SetWheelState(false);
	else { LaunchShip(m_ship); return false; }

	double timestep = Pi::game->GetTimeStep();
	vector3d targpos = Targpos();		// target position in ship's frame
	vector3d obspos = m_obstructor->GetPositionRelTo(m_ship);
	double obsdist = obspos.Length();
	vector3d obsdir = obspos / obsdist;
	vector3d relpos = targpos - m_ship->GetPosition();

	// if too far away, fly to tangent
	if (obsdist > 1.1*m_alt)
	{
		double v;
		Frame *obsframe = GetNonRotFrame(m_obstructor);
		vector3d tangent = GenerateTangent(m_ship, obsframe, targpos, m_alt);
		vector3d tpos_obs = GetPosInFrame(obsframe, m_ship->GetFrame(), targpos);
		if (m_targmode != 1 && m_targmode != 2) v = m_vel;
		else if (relpos.LengthSqr() < obsdist) v = 0.0;
		else v = MaxVel((tpos_obs-tangent).Length(), tpos_obs.Length());
		m_child = new AICmdFlyTo(m_ship, obsframe, tangent, v, true);
		ProcessChild(); return false;
	}

	// limit m_vel by target proximity & distance covered per frame
	double vel = (m_targmode != 1 && m_targmode != 2) ? m_vel
		: MaxVel(relpos.Length(), targpos.Length());

	// all calculations in ship's frame
	vector3d fwddir = (obsdir.Cross(relpos).Cross(obsdir)).Normalized();
	vector3d tanvel = vel * fwddir;

	// frame body suicide check, response
	if (CheckSuicide(m_ship, -obsdir)) {
		m_ship->AIFaceDirection(m_ship->GetPosition());		// face away from planet
		m_ship->AIMatchVel(vector3d(0.0)); return false;
	}

	// max feature avoidance check, response
	if (obsdist < MaxFeatureRad(m_obstructor)) {
		double ang = m_ship->AIFaceDirection(-obsdir);
		m_ship->AIMatchVel(ang < 0.05 ? 1000.0 * -obsdir : 0.0);
		return false;
	}

	// calculate target velocity
	double alt = (tanvel * timestep + obspos).Length();		// unnecessary?
	double ivel = calc_ivel(alt - m_alt, 0.0, m_ship->GetAccelMin());

	vector3d finalvel = tanvel + ivel * obsdir;
	m_ship->AIMatchVel(finalvel);
	m_ship->AIFaceDirection(fwddir);

//	vector3d newhead = GenerateTangent(m_ship, m_obstructor->GetFrame(), fwddir);
//	newhead = GetPosInFrame(m_ship->GetFrame(), m_obstructor->GetFrame(), newhead);
//	m_ship->AIFaceDirection(newhead-m_ship->GetPosition());

	// termination condition for orbits
	vector3d thrust = m_ship->GetThrusterState();
	if (m_targmode >= 3 && thrust.LengthSqr() < 0.01) m_targmode++;
	if (m_targmode == 5) { m_ship->SetThrusterState(vector3d(0.0)); return true; }
	return false;
}