void BulletDebugDrawer::drawLine( const btVector3& from, const btVector3& to, const btVector3& color )
	{
		ci::ColorA colorA = ci::ColorA( color.getX(), color.getY(), color.getZ() );

		ci::gl::color( colorA );
		ci::gl::drawLine( fromBullet( from ), fromBullet( to ) );
	}
bool Context::closestRayCast( const ci::vec3 &startPosition, const ci::vec3 &direction, RayResult &result )
{
	if( ! world() )
		return false;
	
	btVector3 rayTo = toBullet( direction * 1000.0f );
	btVector3 rayFrom = toBullet( startPosition );
	
	btCollisionWorld::ClosestRayResultCallback rayCallback( rayFrom, rayTo );
	
	world()->rayTest( rayFrom, rayTo, rayCallback );
	
	if( rayCallback.hasHit() ) {
		
		btRigidBody* pBody = (btRigidBody*) btRigidBody::upcast( rayCallback.m_collisionObject );
		
		if(!pBody)
			return false;
		
		result.pBody = pBody;
		result.hitPoint = fromBullet( rayCallback.m_hitPointWorld );
		result.hitNormal = fromBullet( rayCallback.m_hitNormalWorld );
		
		return true;
	}
	
	return false;
}
	void BulletDebugDrawer::drawSphere( btScalar radius, const btTransform& transform, const btVector3& color )
	{
		ci::ColorA colorA = ci::ColorA( color.getX(), color.getY(), color.getZ() );

		ci::gl::enableWireframe();
		ci::gl::color( colorA );
		ci::gl::pushMatrices();
		ci::gl::translate( fromBullet( transform.getOrigin() ) );
		ci::gl::rotate( fromBullet( transform.getRotation() ) );
		ci::gl::drawSphere( ci::Vec3f::zero(), radius, 20 );
		ci::gl::popMatrices();
		ci::gl::disableWireframe();
	}
	void BulletDebugDrawer::drawCylinder( btScalar radius, btScalar halfHeight, int upAxis, const btTransform& transform, const btVector3& color )
	{
		btIDebugDraw::drawCylinder( radius, halfHeight, upAxis, transform, color );
		return;
		ci::ColorA colorA = ci::ColorA( color.getX(), color.getY(), color.getZ() );

		ci::gl::enableWireframe();
		ci::gl::color( colorA );
		ci::gl::pushMatrices();
		ci::gl::translate( fromBullet( transform.getOrigin() ) );
		ci::gl::rotate( fromBullet( transform.getRotation() ) );
		ci::gl::drawCylinder( radius, radius, halfHeight, 20, 3 );
		ci::gl::popMatrices();
		ci::gl::disableWireframe();
	}
Beispiel #5
0
void reEnemy::messageProcess( reMessageDispatcher* sender, reMessage* message )
{	
	switch (message->id)
	{
	case reM_MOUSE_PRESS:
		{
			reMouseMessage* mouseMessage = (reMouseMessage*)message;
			reVec3 dir = glm::normalize(mouseMessage->dir);
			reVec3 p(0,1,0);
			target = mouseMessage->p + mouseMessage->dir*(glm::dot(p, mouseMessage->p)/glm::dot(p, -mouseMessage->dir));
			reVec3 d = (mouseMessage->p.y / -dir.y) * dir + mouseMessage->p;
			assert(glm::length(d-target) < 0.1f);
		}
		break;
	case reM_TIMER:
		{
			reVec4 pos = worldTransform().matrix * reVec4(0,0,0,1);
			reVec3 dir = target - reVec3(pos);
			if (glm::length(dir)>.5f)
			{
				dir = glm::normalize(dir);
				body->btBody->applyCentralForce(toBullet(dir)*1000);
			}
			else
			{
				dir = -fromBullet(body->btBody->getLinearVelocity());
				body->btBody->applyCentralForce(toBullet(dir)*100);				
			}
			reVec3 v = fromBullet(body->btBody->getLinearVelocity());
			reNode* node = (reNode*)children->objectByName("model");
			reAnimator* animator = node->children->findObject<reAnimator>();
			if (glm::length(v) > 0.001f)
			{
				float angle = atan2(v.x, v.z);				
				node->transform(reTransform(glm::rotate(reMat4(), glm::degrees(angle), reVec3(0,1,0))));				
				animator->play((reSequence*)node->objectByName("walk"), .3);
				animator->stopAnimation("idle", .3);
			}
			else
			{
				animator->play((reSequence*)node->objectByName("idle"), .3);
				animator->stopAnimation("walk", .3);
			}
		}
		break;
	}
}
Beispiel #6
0
void RigidBody::recalculateBoundingSphere()
{
	btVector3 center;
	mCollisionShape->getBoundingSphere( center, mBoundingSphereRadius );
	mBoundingSphereCenter = fromBullet( center );
}
Beispiel #7
0
void rePlayer::messageProcess( reMessageDispatcher* sender, reMessage* message )
{
	reVec3 deltaAngle(0,0,0);
	float rs = .5f;
	switch (message->id)
	{
	case reM_TIMER:
		if (model())
		{
			reVec3 dirZ = reVec3(model()->worldTransform().matrix * reVec4(0,0,-1, 0));
			reVec3 dirX = reVec3(model()->worldTransform().matrix * reVec4(1,0,0, 0));

			if (reRadial::shared()->input()->keyStates['W'])
			{			
				body->btBody->applyCentralForce(toBullet(dirZ * 50.0f));
			}
			if (reRadial::shared()->input()->keyStates['S'])
			{
				body->btBody->applyCentralForce(toBullet(dirZ * -50.0f));
			}
			if (reRadial::shared()->input()->keyStates[' '])
			{			
				body->btBody->applyCentralForce(toBullet(dirX * 1.0f));
				//reVec4 f = worldTransform().matrix * reVec4(0,-200,0,0);
				//btVector3 bf(f.x, f.y, f.z);
				//body->btBody->applyCentralForce(bf);
			}
			if (reRadial::shared()->input()->keyStates['A'])
			{
				reVec3 v = reVec3(glm::rotate(reMat4(), rs, reVec3(0,1,0)) * reVec4(fromBullet(body->btBody->getLinearVelocity()), 0));
				body->btBody->setLinearVelocity(toBullet(v));								
				model()->transform(glm::rotate(reMat4(), rs, reVec3(0,1,0)) * model()->transform().matrix);
				//body->btBody->applyCentralForce(toBullet(f));
			}
			if (reRadial::shared()->input()->keyStates['D'])
			{
				reVec3 v = reVec3(glm::rotate(reMat4(), -rs, reVec3(0,1,0)) * reVec4(fromBullet(body->btBody->getLinearVelocity()), 0));
				body->btBody->setLinearVelocity(toBullet(v));
				model()->transform(glm::rotate(reMat4(), -rs, reVec3(0,1,0)) * model()->transform().matrix);
				//deltaAngle += reVec3(0,-1,0);
				//model()->transform(glm::rotate(reMat4(), -1.0f, reVec3(0,1,0)) * model()->transform().matrix);
			}
			reVec3 pos = worldTransform().position();
			camera->lookAt(pos);
			light->lookAt(pos);
			if (pos.y < calculateVertex(reVec4(pos,1)).y)
			{
				//__debugbreak();
			}
			break;
		}
	}
	
	if (glm::length(fromBullet(body->btBody->getLinearVelocity())))
	{				
		reVec3 dir = glm::normalize(fromBullet(body->btBody->getLinearVelocity()));
		if (!dir.z)
		{
			return;
		}
		float yaw = dir.z < 0 ? glm::atan(dir.x / dir.z) : M_PI - glm::atan(dir.x / -dir.z);
		float pitch = glm::atan(dir.y / abs(dir.z));
		reMat4 y(glm::rotate(reMat4(), glm::degrees(yaw), reVec3(0,1,0)));
		reMat4 p(glm::rotate(reMat4(), glm::degrees(pitch), reVec3(1,0,0)));		
		model()->children->at(0)->transform(p);
		reVec3 da = reVec3(0, glm::degrees(yaw), 0) - camera->lookAngles();
		camera->lookAngles(camera->lookAngles() + da / 5.0f );
	}
}