예제 #1
0
// Handle mouse movement
void _Camera::HandleMouse(int UpdateX, int UpdateY) {

	Yaw += btRadians((btScalar)UpdateX) * Sensitivity[0];
	Pitch += btRadians((btScalar)UpdateY) * Sensitivity[1];
	if(Pitch > PitchLimit)
		Pitch = PitchLimit;
	else if(Pitch < -PitchLimit)
		Pitch = -PitchLimit;

	float AdjustedYaw = Yaw - SIMD_HALF_PI;
	float AdjustedPitch = Pitch + SIMD_HALF_PI;
	float CosPitch = cosf(AdjustedPitch);
	float SinPitch = sinf(AdjustedPitch);
	float CosYaw = cosf(AdjustedYaw);
	float SinYaw = sinf(AdjustedYaw);

	btVector3 Direction(SinPitch * CosYaw, CosPitch, SinPitch * SinYaw);
	switch(Type) {
		case FREEMOVE: {
			Game.Camera->setDirection(Direction.x(), Direction.y(), Direction.z());
		} break;
		case THIRD_PERSON: {
			Game.Camera->setDirection(Direction.x(), Direction.y(), Direction.z());
			Offset = Direction * -Distance;
		} break;
	}
}
btKinematicCharacterController::btKinematicCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis)
{
	m_upAxis = upAxis;
	m_addedMargin = btScalar(0.02);
	m_walkDirection.setValue(0,0,0);
	m_useGhostObjectSweepTest = true;
	m_ghostObject = ghostObject;
	m_stepHeight = stepHeight;
	m_turnAngle = btScalar(0.0);
	m_convexShape=convexShape;	
	m_useWalkDirection = true;	// use walk direction by default, legacy behavior
	m_velocityTimeInterval = 0.0;
	m_verticalVelocity = 0.0;
	m_verticalOffset = 0.0;
	m_gravity = btScalar(9.8 * 3); // 3G acceleration.
	m_fallSpeed = 55.0; // Terminal velocity of a sky diver in m/s.
	m_jumpSpeed = 10.0; // ?
	m_wasOnGround = false;
	m_wasJumping = false;
	m_interpolateUp = true;
	setMaxSlope(btRadians(45.0));
	m_currentStepOffset = 0;
	full_drop = false;
	bounce_fix = false;
}
예제 #3
0
// Constructor
_Camera::_Camera() {
	FollowObject = NULL;
	Type = FREEMOVE;
	Position.setZero();
	LastPosition.setZero();
	Offset.setZero();
	Velocity.setZero();
	Yaw = 0.0f;
	Pitch = 0.0f;
	Distance = 5.0f;

	PitchLimit = btRadians(85);
	Sensitivity[0] = 0.4f;
	Sensitivity[1] = 0.4f;
}
예제 #4
0
CCharacterController::CCharacterController(CCharacter* pEntity, btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight)
{
	m_hEntity = pEntity;
	m_flAddedMargin = 0.02f;
	m_vecMoveVelocity.setValue(0,0,0);
	m_pGhostObject = ghostObject;
	m_flStepHeight = stepHeight;
	m_pConvexShape = convexShape;	
	m_vecGravity = btVector3(0, 0, -9.8f);
	m_vecUpVector = btVector3(0, 0, 1);
	m_vecLinearFactor = btVector3(1, 1, 1);
	m_flMaxSpeed = 55.0; // Terminal velocity of a sky diver in m/s.
	m_flJumpSpeed = 6.0;
	m_bColliding = true;
	SetMaxSlope(btRadians(45.0));
}
예제 #5
0
bulletCharacterController::bulletCharacterController (btPairCachingGhostObject* ghostObject,btConvexShape* convexShape,btScalar stepHeight, int upAxis)
{
	m_upAxis = upAxis;
	m_addedMargin = 0.02;
	m_walkDirection.setValue(0,0,0);
	m_useGhostObjectSweepTest = true;
	m_ghostObject = ghostObject;
	m_stepHeight = stepHeight;
	m_turnAngle = btScalar(0.0);
	m_convexShape=convexShape;	
	m_useWalkDirection = true;	// use walk direction by default, legacy behavior
	m_velocityTimeInterval = 0.0;
	m_verticalVelocity = 0.0;
	m_verticalOffset = 0.0;
	m_gravity = 9.8; // 1G accelation.
	m_fallSpeed = 55.0; // Terminal velocity of a sky diver in m/s.
	m_jumpSpeed = 10.0; // ?
	m_wasOnGround = false;
    m_responseEnabled = true;
	setMaxSlope(btRadians(50.0));
}
btKinematicCharacterController::btKinematicCharacterController( btPairCachingGhostObject* externalGhostObject_,
    btPairCachingGhostObject* internalGhostObject_,
    btScalar stepHeight,
    btScalar constantScale,
    btScalar gravity,
    btScalar fallVelocity,
    btScalar jumpVelocity,
    btScalar recoveringFactor )
{
    m_upAxis = btKinematicCharacterController::Y_AXIS;

    m_walkDirection.setValue( btScalar( 0 ), btScalar( 0 ), btScalar( 0 ) );

    m_useGhostObjectSweepTest = true;

    externalGhostObject = externalGhostObject_;
    internalGhostObject = internalGhostObject_;

    m_recoveringFactor = recoveringFactor;

    m_stepHeight = stepHeight;

    m_useWalkDirection = true;  // use walk direction by default, legacy behavior
    m_velocityTimeInterval = btScalar( 0 );
    m_verticalVelocity = btScalar( 0 );
    m_verticalOffset = btScalar( 0 );

    m_gravity = constantScale * gravity;
    m_fallSpeed = constantScale * fallVelocity; // Terminal velocity of a sky diver in m/s.

    m_jumpSpeed = constantScale * jumpVelocity; // ?
    m_wasJumping = false;

    setMaxSlope( btRadians( 45.0 ) );

    mCollision = true;
}
예제 #7
0
void readNodeHierarchy(TiXmlElement* node,btHashMap<btHashString,int>& name2Shape, btAlignedObjectArray<ColladaGraphicsInstance>& visualShapeInstances,  const btMatrix4x4& parentTransMat)
{
	const char* nodeName = node->Attribute("id");
	printf("processing node %s\n", nodeName);

	
	btMatrix4x4 nodeTrans;
	nodeTrans.setIdentity();

	///todo(erwincoumans) we probably have to read the elements 'translate', 'scale', 'rotate' and 'matrix' in-order and accumulate them...
	{
		for (TiXmlElement* transElem = node->FirstChildElement("matrix");transElem;transElem=node->NextSiblingElement("matrix"))
		{
			if (transElem->GetText())
			{
				btAlignedObjectArray<float> floatArray;
				TokenFloatArray adder(floatArray);
				tokenize(transElem->GetText(),adder);
				if (floatArray.size()==16)
				{
					btMatrix4x4 t(floatArray[0],floatArray[1],floatArray[2],floatArray[3],
									floatArray[4],floatArray[5],floatArray[6],floatArray[7],
									floatArray[8],floatArray[9],floatArray[10],floatArray[11],
									floatArray[12],floatArray[13],floatArray[14],floatArray[15]);

					nodeTrans = nodeTrans*t;
				} else
				{
					printf("Error: expected 16 elements in a <matrix> element, skipping\n");
				}
			}
		}
	}

	{
		for (TiXmlElement* transElem = node->FirstChildElement("translate");transElem;transElem=node->NextSiblingElement("translate"))
		{
			if (transElem->GetText())
			{
				btVector3 pos = getVector3FromXmlText(transElem->GetText());
				//nodePos+= unitScaling*parentScaling*pos;
				btMatrix4x4 t;
				t.setPureTranslation(pos);
				nodeTrans = nodeTrans*t;

			}
		}
	}
	{
		for(TiXmlElement* scaleElem = node->FirstChildElement("scale");
				scaleElem!= NULL; scaleElem= node->NextSiblingElement("scale")) 
		{
			if (scaleElem->GetText())
			{
				btVector3 scaling = getVector3FromXmlText(scaleElem->GetText());
				btMatrix4x4 t;
				t.setPureScaling(scaling);
				nodeTrans = nodeTrans*t;
			}
		}
	}
	{
		for(TiXmlElement* rotateElem = node->FirstChildElement("rotate");
				rotateElem!= NULL; rotateElem= node->NextSiblingElement("rotate")) 
		{
			if (rotateElem->GetText())
			{
				//accumulate orientation
				btVector4 rotate = getVector4FromXmlText(rotateElem->GetText());
				btQuaternion orn(btVector3(rotate),btRadians(rotate[3]));//COLLADA DAE rotate is in degrees, convert to radians
				btMatrix4x4 t;
				t.setPureRotation(orn);
				nodeTrans = nodeTrans*t;
			}
		}
	}
	
	nodeTrans = parentTransMat*nodeTrans;
	
	for (TiXmlElement* instanceGeom = node->FirstChildElement("instance_geometry");
				instanceGeom!=0;
				instanceGeom=instanceGeom->NextSiblingElement("instance_geometry"))
	{
		const char* geomUrl = instanceGeom->Attribute("url");
		printf("node referring to geom %s\n", geomUrl);
		geomUrl++;
		int* shapeIndexPtr = name2Shape[geomUrl];
		if (shapeIndexPtr)
		{
			int index = *shapeIndexPtr;
			printf("found geom with index %d\n", *shapeIndexPtr);
			ColladaGraphicsInstance& instance = visualShapeInstances.expand();
			instance.m_shapeIndex = *shapeIndexPtr;
			instance.m_worldTransform = nodeTrans;
		} else
		{
			printf("geom not found\n");
		}
	}

	for(TiXmlElement* childNode = node->FirstChildElement("node");
			childNode!= NULL; childNode = childNode->NextSiblingElement("node")) 
	{
		readNodeHierarchy(childNode,name2Shape,visualShapeInstances, nodeTrans);
	}
}
KinematicCharacterController::KinematicCharacterController(PairCachingGhostObject^ ghostObject,
	ConvexShape^ convexShape, btScalar stepHeight, int upAxis)
{
	_addedMargin = btScalar(0.02);
	_convexShape = convexShape;
	_fallSpeed = 55.0; // Terminal velocity of a sky diver in m/s.
	_ghostObject = ghostObject;
	_gravity = btScalar(9.8 * 3); // 3G acceleration.
	_interpolateUp = true;
	_jumpSpeed = btScalar(10.0); // ?
	_stepHeight = stepHeight;
	_upAxis = upAxis;
	_useGhostObjectSweepTest = true;
	_useWalkDirection = true;	// use walk direction by default, legacy behavior
	
	MaxSlope = btRadians(45.0);
}

KinematicCharacterController::KinematicCharacterController(PairCachingGhostObject^ ghostObject,
	ConvexShape^ convexShape, btScalar stepHeight)
{
	_addedMargin = btScalar(0.02);
	_convexShape = convexShape;
	_fallSpeed = btScalar(55.0); // Terminal velocity of a sky diver in m/s.
	_ghostObject = ghostObject;
	_gravity = btScalar(9.8 * 3); // 3G acceleration.
	_interpolateUp = true;
	_jumpSpeed = btScalar(10.0); // ?
	_stepHeight = stepHeight;
	_upAxis = 1;
	_useGhostObjectSweepTest = true;
예제 #9
0
파일: World.cpp 프로젝트: tbastos/solid
World::Box& World::addRandomBox(const glm::vec3& pos) {
  glm::vec3 color(_rand(_mt), _rand(_mt), _rand(_mt));
  return addBox(btVector3(pos.x, pos.y, pos.z), _rand(_mt) * btRadians(90.0f),
                0, 0, color);
}
예제 #10
0
Hexapod::Hexapod ( btDynamicsWorld* ownerWorld, const btVector3& positionOffset,
	btScalar scale_hexapod,unsigned int _podid)	: m_ownerWorld (ownerWorld), 
                            BodyPart(ownerWorld),
                            m_ctrlParams(),
                            m_legs(),
                            m_rightlegs(),
                            m_shapes(),
                            m_bodies(),
                            m_joints(),
                            m_leftLegs(),
                            m_forces(),
                            m_replys()
{
    podid = _podid;
    param_idx = 0;
    stepping = false;
    //HpodCtrlParams empty;    
    //m_ctrlParams.push_back(empty);
    //m_ctrlParams.clear();
    
    //std::vector<HpodCtrlParams> m_ctrlParams;
    //m_forces.push_back(btVector3(0.f,0.f,0.f));
    //m_forces.clear();

    //HpodReply empty_reply;
    //std::vector<HpodReply> m_replys;
    //m_replys.push_back(empty_reply);
    //m_replys.clear();
    
    
    btVector3 xaxis;
    xaxis.setValue(btScalar(1.), btScalar(0.), btScalar(0.));
    
    btVector3 yaxis;
    yaxis.setValue(btScalar(0.), btScalar(1.), btScalar(0.));
    
    btVector3 zaxis;
    zaxis.setValue(btScalar(0.), btScalar(0.), btScalar(1.));
    
    btTransform offset; offset.setIdentity();
	offset.setOrigin(positionOffset); 
    
    // Setup the geometry
	
#ifdef BODY_SHAPE_BOX
    m_shapes[BODY_THORAX] = new btBoxShape(btVector3(
                                                     btScalar(scale_hexapod*BODY_WIDTH),
                                                     btScalar(scale_hexapod*BODY_HEIGHT),
                                                     btScalar(scale_hexapod*BODY_LENGTH)));
#else
    m_shapes[BODY_THORAX] = new btCapsuleShapeZ(btScalar(scale_hexapod*BODY_WIDTH*1.2),  
                                               btScalar(scale_hexapod*BODY_LENGTH*1.5));
#endif
    
	btTransform transform;
	transform.setIdentity();
    //btTransform rotateBodyT; rotateBodyT.setIdentity();
    //btQuaternion rotateBodyQ;
    //rotateBodyQ.setRotation(xaxis, btRadians(90));
    //rotateBodyT.setRotation(rotateBodyQ);
    
    
    btScalar bodymass;
    
#ifdef FREEZE
    bodymass = 0.f;
#else
    bodymass = 10.f;
#endif
    
    m_bodies[BODY_THORAX] = localCreateRigidBody(bodymass, offset*transform, m_shapes[BODY_THORAX]);   
	transform.setIdentity();
	transform.setOrigin(btVector3(btScalar(0.), btScalar(scale_hexapod*1.6), btScalar(0.)));
    
    body = m_bodies[BODY_THORAX];
    
	// Setup some damping on the m_bodies
	for (int i = 0; i < BODYPART_COUNT; ++i)
	{
		m_bodies[i]->setDamping(0.05f, 0.85f);
		m_bodies[i]->setDeactivationTime(0.8f);
		m_bodies[i]->setSleepingThresholds(1.6f, 2.5f);
	}
    
    

    
    
    btQuaternion leftLegQuat, rightLegQuat;
    btQuaternion upQuat;
    upQuat.setRotation(zaxis, btRadians(90));
    leftLegQuat.setRotation(yaxis,  btRadians(0));
    leftLegQuat*=upQuat;
    rightLegQuat.setRotation(yaxis, btRadians(180));
    rightLegQuat*=upQuat;
 
    btTransform legPosTransform, legRotTransform;
    legPosTransform.setIdentity(); legRotTransform.setIdentity();
    
    legPosTransform.setRotation(leftLegQuat);
    legPosTransform.setOrigin(
        btVector3(btScalar(LEFT_SIDE*scale_hexapod*BODY_WIDTH),
                  btScalar(BOTTOM_SIDE*scale_hexapod*BODY_HEIGHT*0.5),
                  btScalar(FRONT_SIDE*scale_hexapod*BODY_LENGTH)));
                                 
    legs[FRONT_LEFT] = new Leg(this, m_ownerWorld,offset,legPosTransform*legRotTransform,scale_hexapod,true);
 
    
    legPosTransform.setRotation(rightLegQuat);
    legPosTransform.setOrigin(
                              btVector3(btScalar(RIGHT_SIDE*scale_hexapod*BODY_WIDTH),
                                        btScalar(BOTTOM_SIDE*scale_hexapod*BODY_HEIGHT*0.5),
                                        btScalar(FRONT_SIDE*scale_hexapod*BODY_LENGTH)));
    
    legs[FRONT_RIGHT] = new Leg(this, m_ownerWorld,offset,legPosTransform*legRotTransform,scale_hexapod);
    
    
    legPosTransform.setRotation(leftLegQuat);
    legPosTransform.setOrigin(
                              btVector3(btScalar(LEFT_SIDE*scale_hexapod*BODY_WIDTH),
                                        btScalar(BOTTOM_SIDE*scale_hexapod*BODY_HEIGHT*0.5),
                                        btScalar(CENTER_SIDE*scale_hexapod*BODY_LENGTH)));
    
    legs[MIDDLE_LEFT] = new Leg(this, m_ownerWorld,offset,legPosTransform*legRotTransform,scale_hexapod,true);
    
    
    
    legPosTransform.setRotation(rightLegQuat);
    legPosTransform.setOrigin(
                              btVector3(btScalar(RIGHT_SIDE*scale_hexapod*BODY_WIDTH),
                                        btScalar(BOTTOM_SIDE*scale_hexapod*BODY_HEIGHT*0.5),
                                        btScalar(CENTER_SIDE*scale_hexapod*BODY_LENGTH)));
    
    legs[MIDDLE_RIGHT] = new Leg(this, m_ownerWorld,offset,legPosTransform*legRotTransform,scale_hexapod);
    
    
    legPosTransform.setRotation(leftLegQuat);
    legPosTransform.setOrigin(
                              btVector3(btScalar(LEFT_SIDE*scale_hexapod*BODY_WIDTH),
                                        btScalar(BOTTOM_SIDE*scale_hexapod*BODY_HEIGHT*0.5),
                                        btScalar(REAR_SIDE*scale_hexapod*BODY_LENGTH)));
    
    legs[REAR_LEFT] = new Leg(this, m_ownerWorld,offset,legPosTransform*legRotTransform,scale_hexapod,true);
    
    legPosTransform.setRotation(rightLegQuat);
    legPosTransform.setOrigin(
                              btVector3(btScalar(RIGHT_SIDE*scale_hexapod*BODY_WIDTH),
                                        btScalar(BOTTOM_SIDE*scale_hexapod*BODY_HEIGHT*0.5),
                                        btScalar(REAR_SIDE*scale_hexapod*BODY_LENGTH)));
    
    legs[REAR_RIGHT] = new Leg(this, m_ownerWorld,offset,legPosTransform*legRotTransform,scale_hexapod);
    
    m_legs.push_back(legs[FRONT_LEFT]);
    m_legs.push_back(legs[FRONT_RIGHT]);
    m_legs.push_back(legs[MIDDLE_LEFT]);
    m_legs.push_back(legs[MIDDLE_RIGHT]);
    m_legs.push_back(legs[REAR_LEFT]);
    m_legs.push_back(legs[REAR_RIGHT]);
    
    m_leftLegs.push_back(legs[FRONT_LEFT]);
    m_leftLegs.push_back(legs[MIDDLE_LEFT]);
    m_leftLegs.push_back(legs[REAR_LEFT]);
    
    m_rightlegs.push_back(legs[FRONT_RIGHT]);
    m_rightlegs.push_back(legs[MIDDLE_RIGHT]);
    m_rightlegs.push_back(legs[REAR_RIGHT]);
    
    legs[REAR_LEFT]->knee->getMotorTargetVelosity();  // WTH with spelling error
    goDefaultPos();
    
}