示例#1
0
/**
* LookTowards
*
* Note 1: Function will exit if front_vec is (close to) parallel to the Y-axis; supply your own up_vec if this is the case.
* Note 2: Not fully tested, use at own risk...
*
* Example:
*	Make camera look at 'my_node'. Note that world space positions are used.
*	camera->lookAt( my_node->getWorldPosition() - camera->getWorldPosition() );
*/
void Transformable::lookTowards(
		vec3f	front_vec,
		vec3f	up_vec
	)
{
	vec3f right;
	vec3f up;
	vec3f prev_up;

	front_vec.normalize();
	up_vec.normalize();

	if (abs(up_vec.dot(front_vec)) > 0.99999f) {
		return;
	}

	if (parent && parent->is_transformable) {
		mat3f mat;
		R = ((Transformable *) parent)->getWorldMatrix().rotationMatrix();
		R.inv();

		prev_up = up_vec;

		right = front_vec.cross(prev_up);
		up = right.cross(front_vec);

		right.normalize();
		up.normalize();

		mat.setCol(0, right);
		mat.setCol(1, up);
		mat.setCol(2, -front_vec);

		R = R * mat;

	} else {
		prev_up = up_vec;

		right = front_vec.cross(prev_up);
		up = right.cross(front_vec);

		right.normalize();
		up.normalize();

		R.setCol(0, right);
		R.setCol(1, up);
		R.setCol(2, -front_vec);
	}
}
vec3f vec3f::random(){
	static vec3f rnd;
	rnd.x=random_double()*2-1;
	rnd.y=random_double()*2-1;
	rnd.z=random_double()*2-1;
	rnd.normalize();
	return rnd;
}
示例#3
0
bool Entity::accumulateForce(vec3f steeringToAdd)
{
    float forceUsed = mSteeringForce.getLength();
    float forceRemaining = mMaxForce - forceUsed;
    
    if (forceRemaining <= 0)
        return false;
        
    float forceToAdd = steeringToAdd.getLength();
    
    if (forceToAdd < forceRemaining)
    {
        mSteeringForce += steeringToAdd;
    }
    else
    {
        steeringToAdd.normalize();
        mSteeringForce += steeringToAdd * forceRemaining;
    }
    
    return true;
}
示例#4
0
void Entity::setVelocity(vec3f velocity)
{
    velocity.normalize();
    mVelocity = velocity * mMaxSpeed;
}