I made some quick additions to fulcrums physics as a working example of character controllers. It allows you to zoom in and out using dbMouseZ() and dbPitchCameraDown() with a couple of home brewed functions.
I think its a pretty good working example of how to zoom and auto pitch with zoom. I added comments so should be easy to figure out.
I'll be adding alot more as I go on and hopefully it helps someone struggling like I do so often.
// In this example we will look at getting your character walking around a level
// using a character controller, this is a special kind of kinematic dynamic actor.
// Because it is kinematic it is not affected by forces, it is designed to give you
// direct control over your characters. There are two types of controller, capsule
// and box, both have slightly different characteristics but basically do the same
// thing.
#define WIN32_LEAN_AND_MEAN
#include "DarkGDK.h"
#include "FulcrumPhy.h"
void controlCharacter(int objectID, float turnSpeed, float walkSpeed, float gravity);
void updateAnimation(int objectID, int firstFrame, int lastFrame);
void updateCamera(int objectID, float distance, float height, float smooth);
FulcrumPhy myPhysics;
float distance;//declare distance of type float for camera distance
float height;//declare height of type float for camera pitch
void clamp_distance(float result, float min, float max)//handy function to clamp two values to a result
{
if(distance > max) result = max;
if(distance < min) result = min;
distance = result;
}
void clamp_height(float result, float min, float max)//handy function to clamp two values to a result
{
if(height > max) result = max;
if(height < min) result = min;
height = result;
}
void DarkGDK ( void )
{
myPhysics.start(true);
dbSetDisplayMode(1024,768,32);
dbSyncOn ( );
dbSyncRate ( 60 );
dbRandomize ( dbTimer ( ) );
dbLoadObject("..//Media//Babe//H-Babe-Move.x", 1);
dbLoadObject("..//Media//TestLevel//TestMap.dbo", 2);
dbScaleObject(2, 10, 10, 10);
myPhysics.makeTriangleMeshFromDBO(2);
// Here, I will show how to make both types of controllers, for each type there are
// two overloads for the respective 'make' functon, one tries to set up your character
// size and offset along the y-axis automatically while the other gives you a little
// more control. The box controller below uses the first way while the capsule controller
// uses the second.
myPhysics.makeControllerCapsule(1, 0.1, 45, dbObjectSizeX(1), dbObjectSizeY(1));
//myPhysics.makeControllerBox(1, 0.2, 45, true);
myPhysics.positionCharacterController(1, 0, 5, 0);
myPhysics.setControllerLocalPositionY(1, -1.05); //Not needed for box controller here
myPhysics.simulate();
while ( LoopGDK ( ) )
{
distance = dbMouseZ() * 0.01;//dbMouseZ() factored by a float gives smooth transition
clamp_distance(distance, 0.5, 10.0);///a function that clamps a min and max to a result
height = dbMouseZ() * 0.01;//dbMouseZ() factored by a float gives smooth transition
clamp_height(height, 4.0, 10.0);////a function that clamps a min and max to a result
myPhysics.getPhysicsResults();
controlCharacter(1, 1.0f, 0.1f, -0.3f);
updateAnimation(1, 4, 26);
myPhysics.update();
updateCamera(1, distance, height, 10.0);//distance and height is a variable of void clamp_*
float result = dbATANFULL(2.0, distance);/////get the factor of a tangeant between and copy to a result
dbPitchCameraDown(result);/////apply result to camera pitch
myPhysics.simulate();
dbSync ( );
}
myPhysics.stop();
return;
}
void controlCharacter(int id, float turnSpeed, float walkSpeed, float gravity)
{
if(dbLeftKey())
dbRotateObject(id, 0, dbObjectAngleY(id) - turnSpeed, 0);
if(dbRightKey())
dbRotateObject(id, 0, dbObjectAngleY(id) + turnSpeed, 0);
if(dbUpKey())
walkSpeed = -walkSpeed;
else if(dbDownKey())
walkSpeed = walkSpeed;
else
walkSpeed = 0.0f;
myPhysics.moveCharacterController(id, walkSpeed, gravity);
}
void updateCamera(int id, float distance, float height, float smooth)
{
dbSetCameraToFollow(dbObjectPositionX(id), //PositionX
dbObjectPositionY(id), //PositionY
dbObjectPositionZ(id), //PositionZ
dbObjectAngleY(id) + 180, //Angle
distance, //Distance
height, //Height
smooth, //Smooth
1); //Collision
dbRotateCamera(0, dbObjectAngleY(id) + 180, 0);
}
void updateAnimation(int id, int firstFrame, int lastFrame)
{
if(dbUpKey())
dbSetObjectFrame(id, dbObjectFrame(id) + 1);
if(dbDownKey())
dbSetObjectFrame(id, dbObjectFrame(id) - 1);
if(dbObjectFrame(id) > lastFrame)
dbSetObjectFrame(id, firstFrame);
if(dbObjectFrame(id) < firstFrame)
dbSetObjectFrame(id, lastFrame);
}
DBP 7.0
Asus P5Q MB, P3.0 dual core, 4gigs ram, SATA HD, GTX 260
Vista Ultimate.