Ejemplo n.º 1
0
long ExtObject::aRotateToPosition(LPVAL params)
{
	float x1 = info.x;
	float y1 = info.y;
	float x2 = params[0].GetFloat();
	float y2 = params[1].GetFloat();

	float targetAngle = DEGREES(atan2(y2 - y1, x2 - x1));
	
	info.angle = RotateTowards(info.angle, targetAngle, params[2].GetFloat());
	pRuntime->UpdateBoundingBox(this);

	return 0;
}
Ejemplo n.º 2
0
long ExtObject::aRotateToObject(LPVAL params)
{
	CRunObject* pTarget = params[0].GetPairedObjectParam(pRuntime, this);
	if (pTarget == NULL) return 0;

	float x1 = info.x;
	float y1 = info.y;
	float x2 = pTarget->info.x;
	float y2 = pTarget->info.y;

	float targetAngle = DEGREES(atan2(y2 - y1, x2 - x1));
	
	info.angle = RotateTowards(info.angle, targetAngle, params[1].GetFloat());
	pRuntime->UpdateBoundingBox(this);

	return 0;
}
void Entity::rotate(glm::vec3 rotation)
{
	
	this->_modelMatrix = glm::rotate(this->_modelMatrix, rotation.x, glm::vec3(1.0f, 0.0f, 0.0f));
	this->_modelMatrix = glm::rotate(this->_modelMatrix, rotation.y, glm::vec3(0.0f, 1.0f, 0.0f));
	this->_modelMatrix = glm::rotate(this->_modelMatrix, rotation.z, glm::vec3(0.0f, 0.0f, 1.0f));
	
	//Quaternion to avoid Gimbol Lock
	glm::vec3 gPosition1(-1.5f, 0.0f, 0.0f);
	glm::vec3 gPosition2( 1.5f, 0.0f, 0.0f);
	glm::vec3 desiredDir = gPosition1-gPosition2;
	glm::vec3 desiredUp = glm::vec3(0.0f, 0.0f, 1.0f); // +Y
 
	// Compute the desired orientation
	glm::quat targetOrientation = glm::normalize(LookAt(desiredDir, desiredUp));
 
	// And interpolate
	glm::quat gOrientation2 = RotateTowards(gOrientation2, targetOrientation, 1.0f*0.5f);
	
}
Ejemplo n.º 4
0
void CCruiser::Move(float delta)
{
	switch (mState)
	{
	case State::Enter:
		//Move downwards
		mModel->MoveZ(GetSpeed() * -delta);

		if (AREA_BOUNDS_TOP - (2.0f * GetRadius()) > mModel->GetZ())
		{
			mState = State::Rotate;
		}
		break;
	case State::Attack:
		break;
	case State::Rotate:
	{
		RotateTowards((*mpPlayers)[0]->GetCenterPoint(), delta * kRotateSpeed);

		float bearingToTarget = BearingTowards((*mpPlayers)[0]->GetCenterPoint());
		float rotation = GetRotation();

		float rotDif = bearingToTarget > rotation ? bearingToTarget - rotation : rotation - bearingToTarget;

		if (rotDif < kRotationMargin)
		{
			mState = State::Attack;
			mWeapon->SetFiring(true);
			mStateTimer = 0.0f;
		}
	}
		break;
	default:
		break;
	}
}