A basic sample?

A basic sample?

Hello i'm new to havok and also new to c++

I have been looking into havok for some time now, but i quite dont understand the samples yet.
So i would like to have a standalone sample where i can see a small plane and a box falling and colliding with the plane
with simple/basic functions like createworld, createbox, positionbox etc.
And with minimal 3d graphics, or in the way so that i understand, where is a graphical part and where is a physical part
It would be also nice to be commented. where and what is important to use or import.

In this way i think it would be a good learning sample for a beginner with some basic programming skills, like me.

If some one can do this for me, id be more than happy!
Thanks for reading and sorry for my bad english.

Cheers!

23 posts / 0 new
Last post
For more complete information about compiler optimizations, see our Optimization Notice.

Hi,

There is a standalone program included in the demos, you'll find it in the folder "StandAloneDemos". It does pretty much what you ask for, but it doesn't include any graphics part. It sets up a visual debugger server, so you can use that to see what it does.

You are not indicating your level of experience, so I'm asking : Are you familiar with any kind of 3D programming in C++? If not, I suggest that is where you start. You would want to be reasonably comfortable with creating 3D shapes, cameras, lights, etc. before adding a physics/collision detection library. You do need some kind of rudimentary graphics framework.

The demos, together with the manual and quickstart guide really provide everything you need to get started, but without any experience with 3D graphics programming it would be difficult.

Its a fair bit of work to create even the simplest complete standalone program that includes a graphics framework, and unless someone has one ready to give away (I don't), I doubt your request for such an application has much chance of success. Sory.

If you tell what sort of graphics programming experience you do have, I may be able to point you to some sample code and tutorials that may help lead you towards your goal.

Hope this helps

Cheers

well im new to c++ i have some knowledge in blitz3d but its all basic, i have done lots of stuff in there for testing, my idea was to write a wrapper for blitz3d so that i can use havoks functions and see how stable is blitz3d with it.
I have a wrapper tutorial that is pretty good and i can understand it, but what i dont understand yet is how the havok works, mainly because of poor knowledge in c++

the tutorial itslef is here:
http://www.svenberra.net/wraptutor.zip
(if there is a need i can upload my modifyed version)

i have tried to modify it so that the first function would create the world,
second will do a rigid body, third will tell me the cordinates of the body, fourth will step the physics and the final oen will clear physics but i dont know something is wrong, while i compile i get a message that it cant find the include files .. but the setup should be ok, so i think the problem here is my noobines in c++

Oh and bout the standaloen app that came with havok, it was more dificult for me to understand than the demos, i understand the demos mostly but every demo seems to be built up completeley differently, includes and stuff like that
I was hopin for a simple sample looking the same as the demos, but in a "standalone" way, so that there are no other samples, because all of the other samples that are in the demo, are all more advance than i ask for.

I'm really sorry for my stupitidi but i only want to learn and understand this stuff.

Hello,

Well, I'm afraid I can't help you with your blitz3d wrapper project, I have no experience with blitz3d.

Regarding the Havok demos, this is how I see it: all the Demos are built up the same, ie they all use the demo framework, and each demo only includes the header files it needs. Sure there is a minimum set of required headers, but beyond that, you include the ones you need in order to get Havok to do the job you want it to do.

At the end of my post, you'll find some pseudo-code that shows the minimum set of Havok headers required (for my application). But, it has nothing to do with blitz3d. Have you tried the blitz3d forums?

Your compiler gives you error messages, you need to do something to fix these error messages in order to progress. What are the messages? Which compiler? If it complains that it can't find include files then you have to tell it where to find the include files.

I'm not sure this is going to be of any help to you, but here it is anyway:

// the havok includes
#include 
#include 
#include 
#include 
#include 

#include 
#include 
#include 

#include 
#include 						
#include 		

#include 
#define HK_CLASSES_FILE 
#include 
#include 

// declare this somewhere, its the Havok world
hkpWorld* gHavokWorld;

// define this function somewhere
static void HK_CALL errorReport(const char* msg, void*)
{
	//put code to write msg to the console, or a log file, or just ignore it
	//Havok does sometimes give you helpful hints here, and of course error messages
}

// App main entry point, for me this is in 
INT WINAPI WinMain( HINSTANCE, HINSTANCE, LPSTR, int )
{
	/*
	.
	.	..code..
	.
	*/

	// at this point, my graphics world exists
	// ie. device init, load meshes, setup lights, camera, etc.
	// so here we begin Havok initialisation/setup
	hkResult ret;
	hkPoolMemory* memoryManager = new hkPoolMemory();
	hkThreadMemory* threadMemory = new hkThreadMemory(memoryManager);
	ret = hkBaseSystem::init( memoryManager, threadMemory, errorReport );
	memoryManager->removeReference();
	char* stackBuffer;
	{
		int stackSize = 2*1024*1024;
		stackBuffer = hkAllocate( stackSize, HK_MEMORY_CLASS_BASE);
		hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);
	}

	InitPhysics();	// see below

	YourMainLoop();	// perform game logic, step the havok world, display your graphics

	MaybeSomeCleanupHere();  

	delete gHavokWorld;
	threadMemory->setStackArea(0, 0);
	hkDeallocate(stackBuffer);
	threadMemory->removeReference();
	ret = hkBaseSystem::quit();

	return someExitCode;
}

void InitPhysics()
{
	hkpWorldCinfo info;
	info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;
	info.m_gravity.set( 0, -9.81f, 0);  
	info.m_collisionTolerance = 0.01f;
	info.setBroadPhaseWorldSize( 1000.0f );  
	info.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_8ITERS_MEDIUM );
	gHavokWorld = new hkpWorld(info);	// create the havok world
	hkpAgentRegisterUtil::registerAllAgents( gHavokWorld->getCollisionDispatcher() );

	//now create the physical representation of your world, ie havok entities
	//if, lets say, you have a sphere in your display world, create a havok sphere
	//and put it in the same position as your display mesh. 
}


void YourMainLoop()
{
	/*
	.
	.	do stuff
	.
	*/
	// update the havok world
	gHavokWorld->stepDeltaTime(1/60);
	// and render the graphics
	Render();
	/*
	.
	. do more stuff
	.
	.
	*/
}


//in your render loop,
//get the havok sphere transform and feed it to your display matrix
//for me (using the DirectX SDK), this goes something like:
void Render()
{
	/*
	.
	.	do stuff
	.
	*/

	//get the havok transform of your body
	hkTransform t(yourHavokRigidBody->getRotation(), yourHavokRigidBody->getPosition());
	//feed your display mesh matrix with it
	t.get4x4ColumnMajor(yourDisplayMeshMatrix);
	//setup your device transform, FVF, renderstates, etc.
	pd3dDevice->SetTransform( D3DTS_WORLD, &yourDisplayMeshMatrix );
	//.
	//.
	//.
	//and render
	yourDisplayMesh.Render( pd3dDevice, true, true );  
	//or similar, a lot of the above code is platform and implementation specific/dependant
	//blitz3d will probably hide alot of complexity from you, but somewhere
	//you will have to set your display mesh matrix with info you get from havok
	
	/*
	.
	.	do more stuff
	.
	*/
}

Hope this helps,

Cheers

Hello again, and thanks for the reply's they helped me alot but still i cant get it to work the way i want to

Well here is my code:

// PhysicsWrapper.cpp : Defines the exported functions for the DLL application.
//
#include "stdafx.h"

// ************
// * INCLUDES *
// ************
// Math and base include
#include 
#include 
#include 
#include 
#include 
#include 
#include 

// Dynamics includes
#include 
#include 
#include 
#include 
#include 

#include 
#include 

#include 
#include 
#include 

#include 
#include 
#include 

// Visual Debugger includes
//#include 
//#include 

// Keycode
#include 

// ***************
// * HAVOK STUFF *
// ***************
#if !defined USING_HAVOK_PHYSICS
#error Physics is needed.
#endif



// Classlists
#define INCLUDE_HAVOK_PHYSICS_CLASSES
#define HK_CLASSES_FILE 
#include 

// Generate a custom list to trim memory requirements
#define HK_COMPAT_FILE 
#include 

#include 
static void HK_CALL errorReport(const char* msg, void*)
{
printf("%s", msg);
}


//
// Forward declarations
//
hkpWorld* gHavokWorld;
hkJobThreadPool* threadPool;
char* stackBuffer;
hkResult ret;
hkJobQueue* jobQueue;
hkThreadMemory* threadMemory;
//void setupPhysics(hkpWorld* gHavokWorld);
//hkpRigidBody* g_ball;
// ****************
// * DEFFINITIONS *
// ****************
#define BB_EXPORT extern "C" __declspec(dllexport) // this enables exporting
#define BB_INT int __stdcall // for functions with integers ( int = % = integer variables )
#define BB_VOID void __stdcall //for normal functions
#define BB_FLOAT float __stdcall // for functions with floating variables ( float = # = floating point variables )

//now we can write functions like this = BB_EXPORT BB_VOID MyFunction()


// *********
// * WORLD *
// *********

//create world
BB_EXPORT BB_VOID hkCreateWorld(int Enable)
{
//
// Do platform specific initialization
//
#if !defined(HK_PLATFORM_WIN32)
extern void initPlatform();
initPlatform();
#endif
//
// Initialize the base system including our memory system
//
hkpWorld* gHavokWorld;
hkResult ret;
hkPoolMemory* memoryManager = new hkPoolMemory();
//hkThreadMemory* threadMemory
threadMemory = new hkThreadMemory(memoryManager);
ret = hkBaseSystem::init( memoryManager, threadMemory, errorReport );
memoryManager->removeReference();

// We now initialize the stack area
// char* stackBuffer;
{
int stackSize = 2*1024*1024;
stackBuffer = hkAllocate( stackSize, HK_MEMORY_CLASS_BASE);
hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);
}
{

//
// Initialize the multi-threading classes, hkJobQueue, and hkJobThreadPool
//

// They can be used for all Havok multithreading tasks. In this exmaple we only show how to use
// them for physics, but you can reference other multithreading demos in the demo framework
// to see how to multithread other products. The model of usage is the same as for physics.
// The hkThreadpool has a specified number of threads that can run Havok jobs. These can work
// alongside the main thread to perform any Havok multi-threadable computations.
// The model for running Havok tasks in Spus and in auxilary threads is identical. It is encapsulated in the
// class hkJobThreadPool. On PLAYSTATION3 we initialize the SPU version of this class, which is simply a SPURS taskset.
// On other multi-threaded platforms we initialize the CPU version of this class, hkCpuJobThreadPool, which creates a pool of threads
// that run in exactly the same way. On the PLAYSTATION3 we could also create a hkCpuJobThreadPool. However, it is only
// necessary (and advisable) to use one Havok PPU thread for maximum efficiency. In this case we simply use this main thread
// for this purpose, and so do not create a hkCpuJobThreadPool.
// hkJobThreadPool* threadPool;

// We can cap the number of threads used - here we use the maximum for whatever multithreaded platform we are running on. This variable is
// set in the following code sections.
int totalNumThreadsUsed;

// Get the number of physical threads available on the system
hkHardwareInfo hwInfo;
hkGetHardwareInfo(hwInfo);
totalNumThreadsUsed = hwInfo.m_numThreads;

// We use one less than this for our thread pool, because we must also use this thread for our simulation
hkCpuJobThreadPoolCinfo threadPoolCinfo;
threadPoolCinfo.m_numThreads = totalNumThreadsUsed - 1;

// This line enables timers collection, by allocating 200 Kb per thread. If you leave this at its default (0),
// timer collection will not be enabled.
threadPoolCinfo.m_timerBufferPerThreadAllocation = 200000;
threadPool = new hkCpuJobThreadPool( threadPoolCinfo );

// We also need to create a Job queue. This job queue will be used by all Havok modules to run multithreaded work.
// Here we only use it for physics.
hkJobQueueCinfo info;
info.m_jobQueueHwSetup.m_numCpuThreads = totalNumThreadsUsed;
//hkJobQueue* jobQueue//= new hkJobQueue(info);
jobQueue = new hkJobQueue(info);

//
// : Create the physics world.
// At this point you would initialize any other Havok modules you are using.
//
//hkpWorld* gHavokWorld;
{
// The world cinfo contains global simulation parameters, including gravity, solver settings etc.
hkpWorldCinfo worldInfo;

// Set the simulation type of the world to multi-threaded.
worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_MULTITHREADED;
//worldInfo.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;

// Flag objects that fall "out of the world" to be automatically removed - just necessary for this physics scene
worldInfo.m_broadPhaseBorderBehaviour = hkpWorldCinfo::BROADPHASE_BORDER_REMOVE_ENTITY;

// Set real gravity as default
worldInfo.m_gravity.set( 0, -9.81f, 0);

// Set Default Collision Tolerance
worldInfo.m_collisionTolerance = 0.01f;

// Set Default Broad Phase World Size
worldInfo.setBroadPhaseWorldSize( 1000.0f );

// Set Default Solver
worldInfo.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_8ITERS_MEDIUM );

// Create the havok world
gHavokWorld = new hkpWorld(worldInfo);

// When the simulation type is SIMULATION_TYPE_MULTITHREADED, in the debug build, the sdk performs checks
// to make sure only one thread is modifying the world at once to prevent multithreaded bugs. Each thread
// must call markForRead / markForWrite before it modifies the world to enable these checks.
//gHavokWorld->markForWrite();

// Register all collision agents, even though only box - box will be used in this particular example.
// It's important to register collision agents before adding any entities to the world.
hkpAgentRegisterUtil::registerAllAgents( gHavokWorld->getCollisionDispatcher() );

// We need to register all modules we will be running multi-threaded with the job queue
gHavokWorld->registerWithJobQueue( jobQueue );

// Create all the physics rigid bodies
//setupPhysics( gHavokWorld );
gHavokWorld->lock();
}
////*
if (Enable==TRUE)
//
// Create the floor
//
{
hkpRigidBodyCinfo info;
hkVector4 fixedBoxSize(100.0f, 0.5f , 100.0f );
hkpBoxShape* fixedBoxShape = new hkpBoxShape( fixedBoxSize , 0 );

info.m_shape = fixedBoxShape;
info.m_motionType = hkpMotion::MOTION_FIXED;
info.m_position.setZero4();

// Add some bounce.
info.m_restitution = 0.8f;
info.m_friction = 1.0f;

// Create fixed box
hkpRigidBody* floor = new hkpRigidBody(info);
gHavokWorld->addEntity(floor);

floor->removeReference();
fixedBoxShape->removeReference();
}

//*/
}

}

BB_EXPORT BB_VOID hkSetGravity(float X,float Y, float Z)
{
hkpWorldCinfo worldInfo;
worldInfo.m_gravity.set( X, Y, Z);
}

BB_EXPORT BB_VOID hkStepWorld(float timestep)
{
gHavokWorld->unlock();
//gHavokWorld->stepDeltaTime(time);
gHavokWorld->stepMultithreaded( jobQueue, threadPool, timestep );
}
BB_EXPORT BB_VOID hkFreeWorld()
{
//
// Clean up physics
//

// : cleanup physics
{
//gHavokWorld->markForWrite();
gHavokWorld->removeReference();
}

delete jobQueue;

//
// Clean up the thread pool
//
threadPool->removeReference();
//remove world
delete gHavokWorld;
threadMemory->setStackArea(0, 0);
hkDeallocate(stackBuffer);
threadMemory->removeReference();
ret = hkBaseSystem::quit();
}
// **********
// * BODY'S *
// **********
BB_EXPORT BB_VOID hkBodyCreateBox(float x,float y, float z, float mass)
{
// Data specific to this shape.
hkVector4 halfExtents(x,y,z);

/////////////////// SHAPE CONSTRUCTION ////////////////
hkpBoxShape* shape = new hkpBoxShape(halfExtents, 0 );

// rigidbody info
// To illustrate using the shape, first define a rigid body template.
hkpRigidBodyCinfo rbInfo;
rbInfo.m_position.set(0.0f, 0.0f, 0.0f);
rbInfo.m_angularDamping = 0.0f;
rbInfo.m_linearDamping = 0.0f;

rbInfo.m_shape = shape;

// Compute the rigid body inertia.
rbInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA;
rbInfo.m_mass = mass;
hkpInertiaTensorComputer::setShapeVolumeMassProperties( rbInfo.m_shape, rbInfo.m_mass, rbInfo );

// Create a rigid body (using the template above).
hkpRigidBody* rigidBody = new hkpRigidBody(rbInfo);

// Remove reference since the body now "owns" the Shape.
shape->removeReference();
// Finally add body so we can see it, and remove reference since the world now "owns" it.
gHavokWorld->addEntity(rigidBody);
gHavokWorld->removeReference();
rigidBody;
return rbInfo;
}
/*
BB_EXPORT BB_VOID hkBodySetLinVel(float x,float y, float z, RigidBody)
{
hkVector4 vel( x,y,z );
RigidBody->setLinearVelocity( vel );
}

BB_EXPORT BB_FLOAT hkBodyGetX(RigidBody)
{
if (RigidBody)
{
hkVector4 pos = hkpRigidBody* RigidBody->getPosition()
}
return pos(0);
}
BB_EXPORT BB_FLOAT hkBodyGetY(RigidBody)
{
if (RigidBody)
{
hkVector4 pos = hkpRigidBody* RigidBody->getPosition()
}
return pos(1);
}
BB_EXPORT BB_FLOAT hkBodyGetZ(RigidBody)
{
if (RigidBody)
{
hkVector4 pos = hkpRigidBody* RigidBody->getPosition()
}
return pos(2);
}
*/ 

but the way i would like it to work is like this:
hkCreateWorld(true)
- this creates my world,true is for enabling the "plane scene"
mybox=hkBodyCreateBox(x position,y position,z position,mass)
- this is for the first object that i want to create and i want to return it, so that i can get positions and other information from this specific body
hkGetBodyX(mybox)/hkGetBodyY(mybox)/hkGetBodyZ(mybox)
- these functions are for returning the cordinates of the body
hkStepWorl(steps)
- simply update the physics

...i hope that someone can tell me what i need to add and what do define.
Thanks for reading!

Hi,

its been a while...

Its impossible to tell for me where your code goes wrong.

It looks like you've taken the code from the Havok stand-alone-demo and added the blitz bits to it. The stand-alone-demo is a multi-threaded Havok application. This may complicate matters.

I suggest you try a single-threaded application instead. Use the havok init from the code I've supplied. Make sure you include ALL the includes. Keep the application simple at first. Get it to compile first. Maybe even leave out any Havok stuff, just compile the most basic of blitz applications you can do. Then add the Havok stuff, line by line. Don't create any bodies, just get the thing to compile and run with a Havok world object. Once you got that, you can work on adding bodies, move them, display them, etc. etc.

The code I provided in an earlier post is the most basic way to get a Havok world that I know of.

Also, you don't indicate how your code fails. Does it compile? If not, what error messages do you get? Fix all compiler messages one by one until the code compiles and runs. Thats why I'm suggesting you cut it down until you get something that compiles and runs. Then add Havok stuff, one line at the time. Or, one functional unit at the time.

All the best

Hi again and thanks for a reply!

Well i had some other stuff to do..

Anyway it does sucscessfully combile without the rigidbody functions, the world functions work just fine, yes i know it's a multi thread one, i thought it would be better to be multithread, or what do you think? Well you are probably right i should stay to basic's because im a beginner, il rewrite the functions to be as basic as possible.
But i i think the rigid body stuff still wont work, because i dont understand where todefine the rigid body infromation.
Also to get it work... i need to get atleast one rigid body function working and atleast cordinates, so that i can see if it works, and then i can analyze it, on how it work's and learn how to properly define havok stuff.
I've read one of the havoks user manuals, but it's still to blurry for my knowledge, maybe i have ben reading the wrong one?

When i get back to my c++ computer, il see what errors i get and post them here?

Cheers

Sorry for the delay...
Anyway it says :
Error 1 error C2562: 'hkBodyCreateBox' : 'void' function returning a value c:PhysicsWrapper.cpp 315

when i try to return my rigidbody, i need to return it because for further functions, such as "GetPositionX(rigidbody)"

Thanks for reading!

Edit this is my rigid body creation function:

# BB_EXPORT BB_VOID hkBodyCreateBox(float x,float y, float z, float mass) 
# { 
# // Data specific to this shape. 
# hkVector4 halfExtents(x,y,z); 
#  
# /////////////////// SHAPE CONSTRUCTION //////////////// 
# hkpBoxShape* shape = new hkpBoxShape(halfExtents, 0 ); 
#  
# // rigidbody info 
# // To illustrate using the shape, first define a rigid body template. 
# hkpRigidBodyCinfo rbInfo; 
# rbInfo.m_position.set(0.0f, 0.0f, 0.0f); 
# rbInfo.m_angularDamping = 0.0f; 
# rbInfo.m_linearDamping = 0.0f; 
#  
# rbInfo.m_shape = shape; 
#  
# // Compute the rigid body inertia. 
# rbInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; 
# rbInfo.m_mass = mass; 
# hkpInertiaTensorComputer::setShapeVolumeMassProperties( rbInfo.m_shape, rbInfo.m_mass, rbInfo ); 
#  
# // Create a rigid body (using the template above). 
# hkpRigidBody* rigidBody = new hkpRigidBody(rbInfo); 
#  
# // Remove reference since the body now "owns" the Shape. 
# shape->removeReference(); 
# // Finally add body so we can see it, and remove reference since the world now "owns" it. 
# gHavokWorld->addEntity(rigidBody); 
# gHavokWorld->removeReference(); 
# rigidBody; 
# return rbInfo; //If i remove
# }

If i remove "return rbInfo" it compiles perfectly, so my next question is, how can i return a rigid body?

Quoting - smr597
Sorry for the delay...
Anyway it says :
Error 1 error C2562: 'hkBodyCreateBox' : 'void' function returning a value c:PhysicsWrapper.cpp 315

when i try to return my rigidbody, i need to return it because for further functions, such as "GetPositionX(rigidbody)"

Thanks for reading!

Edit this is my rigid body creation function:

# BB_EXPORT BB_VOID hkBodyCreateBox(float x,float y, float z, float mass) 
# { 
# // Data specific to this shape. 
# hkVector4 halfExtents(x,y,z); 
#  
# /////////////////// SHAPE CONSTRUCTION //////////////// 
# hkpBoxShape* shape = new hkpBoxShape(halfExtents, 0 ); 
#  
# // rigidbody info 
# // To illustrate using the shape, first define a rigid body template. 
# hkpRigidBodyCinfo rbInfo; 
# rbInfo.m_position.set(0.0f, 0.0f, 0.0f); 
# rbInfo.m_angularDamping = 0.0f; 
# rbInfo.m_linearDamping = 0.0f; 
#  
# rbInfo.m_shape = shape; 
#  
# // Compute the rigid body inertia. 
# rbInfo.m_motionType = hkpMotion::MOTION_BOX_INERTIA; 
# rbInfo.m_mass = mass; 
# hkpInertiaTensorComputer::setShapeVolumeMassProperties( rbInfo.m_shape, rbInfo.m_mass, rbInfo ); 
#  
# // Create a rigid body (using the template above). 
# hkpRigidBody* rigidBody = new hkpRigidBody(rbInfo); 
#  
# // Remove reference since the body now "owns" the Shape. 
# shape->removeReference(); 
# // Finally add body so we can see it, and remove reference since the world now "owns" it. 
# gHavokWorld->addEntity(rigidBody); 
# gHavokWorld->removeReference(); 
# rigidBody; 
# return rbInfo; //If i remove
# }

If i remove "return rbInfo" it compiles perfectly, so my next question is, how can i return a rigid body?

Hi smr597,

well error C2562 just tells you to check your method declaration, since you return a value, but your declaration doesn't want one.
You may want to change the following line:
BB_EXPORT BB_VOID hkBodyCreateBox(float x,float y, float z, float mass)
into something like this:
hkpRigidBody* hkBodyCreateBox(float x, float y, float z, float mass)
This may compile now. Later at the end of the method definition do the following;
return rigidBody;
and you can work with the rigid body outside the method.

Kind regards
Frederic-Felix

PS: I am not a friend of people telling you to google, but check the first result on error C2562...same information as the first part of my answer.

Hi, frederic-felix, i did what you sayd (both checked the google and replaced my Void with hkpRigidBody*)
but now i get 4 errors that i dont understand, even if i check google

They are:
Error 1 error C2143: syntax error : missing ';' before '*'
Error 3 error C2440: 'return' : cannot convert from 'hkpRigidBody *' to 'int'
Error 4 error C2617: 'hkBodyCreateBox' : inconsistent return statement
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

(P.S. they all come from the same method/function)

Please, what should i do next? Thanks for your time, yes i know im a rookie, but i trie to understand...

Quoting - smr597
Hi, frederic-felix, i did what you sayd (both checked the google and replaced my Void with hkpRigidBody*)
but now i get 4 errors that i dont understand, even if i check google

They are:
Error 1 error C2143: syntax error : missing ';' before '*'
Error 3 error C2440: 'return' : cannot convert from 'hkpRigidBody *' to 'int'
Error 4 error C2617: 'hkBodyCreateBox' : inconsistent return statement
Error 2 error C4430: missing type specifier - int assumed. Note: C++ does not support default-int

(P.S. they all come from the same method/function)

Please, what should i do next? Thanks for your time, yes i know im a rookie, but i trie to understand...

Hi smr597,

no Problem, in my opinion I will always stay a rookie :)

Could you provide the new method declaration? Are you working with header files...have you checked the method declaration there?

Error 1 looks like the compiler doesn't know anything about hkpRigidBody...Do you have all header files included for Havok?

Best regards,
Frederic-Felix

The code is all the same as i posted earlyer, i only changed the line that you sayd, i should do, also i fixed few typos, such as "rigidbody" into "rigidBody".
Anyway, im probably doing something simple wrong... but i cant figure out what, im not that comfortable with C++, im totaly new to it, im learning C++ while creating this, kinda stupid way, this is how spagethy codes are done haha.
But i stil would like to get the wery basic of my program to work, then i could learn more of this havok and C++
My weaknes right now in C++ is that i dont quite understand, why do i have to deffine everything ...well this went a bit offtopic, il try to get a look into the header's and see what i can understand

Quoting - smr597
The code is all the same as i posted earlyer, i only changed the line that you sayd, i should do, also i fixed few typos, such as "rigidbody" into "rigidBody".
Anyway, im probably doing something simple wrong... but i cant figure out what, im not that comfortable with C++, im totaly new to it, im learning C++ while creating this, kinda stupid way, this is how spagethy codes are done haha.
But i stil would like to get the wery basic of my program to work, then i could learn more of this havok and C++
My weaknes right now in C++ is that i dont quite understand, why do i have to deffine everything ...well this went a bit offtopic, il try to get a look into the header's and see what i can understand

Hi smr597,

Unfortunately I can't offer any direct solutions to your problems, but I know of a very good resource that could help you get more comfortable with C++.

Check out "Thinking in C++" Volume 1 and Volume 2, 2nd editions, by Bruce Eckel. They are available to download for free, including all the sample code. I've found these 2 books to be the excellent for learning and understanding C++.

Some thoughts I had regarding your problem:

Declare your function

hkpRigidBody* hkBodyCreateBox(float x, float y, float z, float mass);

in that function, return rigidBody instead of rbInfo. Don't add the rigidBody to the world inside the function. Instead, add it somewhere in the calling code, like

// declare a variable of type pointer to hkpRigidBody
hkpRigidBody* myBody;

// call your function, which returns a pointer to a hkpRigidBody
myBody = hkBodyCreateBox( 20.0f, 20.0f, 20.0f, 50.0f);

// then add it to the havok world
gHavokWorld->addEntity(myBody);

// finally, remove the reference
myBody->removeReference();

Like the other poster mentioned, make sure your function declarations are consistent.

Line 31 in your code says nothing but
rigidBody;
this statement causes error C4430, i think, anyway, it doesn't do anything so just delete it.

Hope this helps a bit

Cheers

Hi delray25

I noticed i had a typo in my deffinition, now i removed the bad code and got it compiled .. but now there are some other problems:

It seems that i get an error when i trie to step the world

Also i simplified my code .. i thook the multithread part out of my code, to keep it simple first.
Well .. here is my world creation and steping

// declarations
hkpWorld* gHavokWorld = NULL;
char* stackBuffer;
hkResult ret;
hkThreadMemory* threadMemory;

//create world
BB_EXPORT  BB_VOID hkCreateWorld(int Enable)
{
	// at this point, my graphics world exists  
	// ie. device init, load meshes, setup lights, camera, etc.  
	// so here we begin Havok initialisation/setup  
	hkResult ret;  
	hkPoolMemory* memoryManager = new hkPoolMemory();  
	hkThreadMemory* threadMemory = new hkThreadMemory(memoryManager);  
	ret = hkBaseSystem::init( memoryManager, threadMemory, errorReport );  
	memoryManager->removeReference();  
	char* stackBuffer;  
	{  
		int stackSize = 2*1024*1024;  
		stackBuffer = hkAllocate( stackSize, HK_MEMORY_CLASS_BASE);  
		hkThreadMemory::getInstance().setStackArea( stackBuffer, stackSize);  
	}
	hkpWorldCinfo info;  
	info.m_simulationType = hkpWorldCinfo::SIMULATION_TYPE_CONTINUOUS;  
	info.m_gravity.set( 0, -9.81f, 0);    
	info.m_collisionTolerance = 0.01f;  
	info.setBroadPhaseWorldSize( 1000.0f );    
	info.setupSolverInfo( hkpWorldCinfo::SOLVER_TYPE_8ITERS_MEDIUM );  
	gHavokWorld = new hkpWorld(info);   // create the havok world  
	hkpAgentRegisterUtil::registerAllAgents( gHavokWorld->getCollisionDispatcher() );  

	//now create the physical representation of your world, ie havok entities  
	//if, lets say, you have a sphere in your display world, create a havok sphere  
	//and put it in the same position as your display mesh.

	////*
	if (Enable==TRUE)
		//
		// Create the floor
		//
		{
		hkpRigidBodyCinfo info;
		hkVector4 fixedBoxSize(100.0f, 0.5f , 100.0f );
		hkpBoxShape* fixedBoxShape = new hkpBoxShape( fixedBoxSize , 0 );

		info.m_shape = fixedBoxShape;
		info.m_motionType = hkpMotion::MOTION_FIXED;
		info.m_position.setZero4();

		// Add some bounce.
		info.m_restitution = 0.8f;
		info.m_friction = 1.0f;

		// Create fixed box
		hkpRigidBody* floor = new hkpRigidBody(info);
		gHavokWorld->addEntity(floor);

		floor->removeReference();
		fixedBoxShape->removeReference();
		}	

}
//stepworld
BB_EXPORT  BB_VOID hkStepWorld(float timestep)
{
	gHavokWorld->stepDeltaTime(timestep);
}

But as i sayd, some strange way, world steping doesn't seem to work, i get a error in my application(an error that has nothing to do with c++).

I think it has something to do with wrongly declaring the world?

Also i have read the first one of these tutorials before , il try to read it again and thake a good look at the other one also.

Well I'm trying to get the rotation into functions like this: hkGetBodyPitch(body)/hkGetBodyYaw(body)/hkGetBodyRoll(body) ... any tips/tricks on how to use "hkQuaternion" or smoething, to achive my needs?

If i could get the world steping working, and return the rotation in Pitch/Yaw/Roll then my basic sample would work i quess .. because right now, my program shows cordinates of the body, but they are "freezed" because i cant step the physics engine...

Thanks for helping me... so far this help has been wery usefull to me!

*** i edited my post several times, because i solved some problems myself, and i dont want to confuse you people overhere, with useless information ***

so nobody knows what and how?

You said "i get a error in my application" - you need to give more details. What's the callstack from the error? Does Havok print out any warnings or asserts first? Make sure you're linking against the Debug Multithreaded or Debug Multithreaded DLL libraries so that Havok's asserts are enabled.

I've never messed with pitch/yaw/roll and there nothing in the Havok math library to extract them. However, you can access the elements of the quaternion like this:

hkQuaternion q = // initialize the quaternion somehow.
float x = q.m_vec(0);
float y = q.m_vec(1);
// etc...

Hope that helps.

-Chris

Quoting - havokchris
You said "i get a error in my application" - you need to give more details. What's the callstack from the error? Does Havok print out any warnings or asserts first? Make sure you're linking against the Debug Multithreaded or Debug Multithreaded DLL libraries so that Havok's asserts are enabled.

I've never messed with pitch/yaw/roll and there nothing in the Havok math library to extract them. However, you can access the elements of the quaternion like this:

hkQuaternion q = // initialize the quaternion somehow.
float x = q.m_vec(0);
float y = q.m_vec(1);
// etc...

Hope that helps.

-Chris

Thanks for a reply

This is the error that i get in my aplication:
"unknown runtime eception"
i'm not quite sure on how t osee the callstack, but i did a debug version and it seems that in my program, it doesn't like to function with hkBaseSystem, i tested multiple times various things and i get that error in a function that has something to do with adding stuff into the havok world and/or when i try to do something with the Base system, for example "hkResult res = hkBaseSystem::quit();"

To make things clear im creating a dll, that i'm using in blitz3d. In C++ it compiles perfectly under debug with debugmemory, but when i trie to run the program in blitz3d, it crashes...

Hi smr597,

Which compiler are you using? If you're using visual studio (either the express version or the payed for versions) there are two ways to run your program from the IDE. One of them is called "start without debugging". It basically just launches your program like a player would. The other is called "start debugging". It launches your program but hooks the IDE into it. Make sure you're running using "start debugging".

Then, when you program crashes, the IDE will break and do its best to show you where in code the problem occurred. Because Havok XS ships with a program debug database (PDB) visual studio should be able to give you an idea of what the callstack looks like way down deep inside Havok. From that we can look through the source ourselves and maybe give you some more information about what might be causing the problem.

Since you're running it through blitz3d you'll need to set up an extra step. I haven't ever played with it but it should work. When you try to run the DLL inside the debugger, it'll ask for the name of the executable file to be used for the debug session. You'll need to find blitz3d. It should then launch blitz3d and you can reproduce the problem and when it crashes the IDE will catch it.

You can also setup your DLL project to know which program to use to debug itself everytime. Check out this MSDN article. Incidentally, since you're writing a DLL anyway, you might want to look in to setting up a unit testing project so you can check that your DLL is running right without launching blitz3d. Google around for "unit testing for games". Then peek over at UnitTest++.

Hope that helps.

-Jay

'Havok Physics 6.exe': Loaded 'C:Havok Physics 6.5.0 R1Blitz3d WrapperPhysicsWrapperblitzbasicHavok Physics 6.exe', Binary was not built with debug information.
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32ntdll.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32kernel32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32user32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32gdi32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32wsock32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32ws2_32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32advapi32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32rpcrt4.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32secur32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32msvcrt.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32ws2help.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32winmm.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32d3dxof.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32dplayx.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32ddraw.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32dciman32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32dinput.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32shell32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32shlwapi.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32ole32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32msacm32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32imm32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSWinSxSx86_Microsoft.Windows.Common-Controls_6595b64144ccf1df_6.0.2600.5512_x-ww_35d4ce83comctl32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32comctl32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32uxtheme.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32msctf.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSBricoPacksVista Inspirat 2UberIconUberIcon.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32version.dll'
'Havok Physics 6.exe': Unloaded 'C:WINDOWSsystem32version.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32msctfime.ime'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32d3dim700.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32hid.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32setupapi.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32wintrust.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32crypt32.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32msasn1.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32imagehlp.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32wdmaud.drv'
'Havok Physics 6.exe': Unloaded 'C:WINDOWSsystem32wdmaud.drv'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32wdmaud.drv'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32msacm32.drv'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32midimap.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32dsound.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32version.dll'
'Havok Physics 6.exe': Loaded 'C:WINDOWSsystem32ksuser.dll'
First-chance exception at 0x1001511b in Havok Physics 6.exe: 0xC0000005: Access violation reading location 0x0000000c.
First-chance exception at 0x7c812afb in Havok Physics 6.exe: Microsoft C++ exception: bbEx at memory location 0x0012f948..
The thread 'Win32 Thread' (0xabc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xedc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xbbc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xfdc) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0x928) has exited with code 0 (0x0).
The thread 'Win32 Thread' (0xea4) has exited with code 0 (0x0).
The program '[3768] Havok Physics 6.exe: Native' has exited with code 0 (0x0).

is this the right thing? well i dont understand abit of it.. i can only see that blitz3d is loading some dll's but i dont see anything that shows wheres my problem, it's probably because im quite new in c++ world

No, it'll look more like this:

> Demos_win32-net_9-0_fulldebug_multithreaded.exe!Gdc2005Demo::loadSceneWithPhysics(const char * filename=0x0240fe10, hkgAssetConverter::ConvertMask convMask=NO_LIGHTS | NO_CAMERAS, int layer=1, int systemGroup=0) Line 137 + 0x7b bytes C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!Gdc2005Demo::initLevel() Line 218 C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!Gdc2005Demo::Gdc2005Demo(hkDemoEnvironment * env=0x001af258) Line 197 C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!hkCreateGdc2005Demo(hkDemoEnvironment * env=0x001af258) Line 901 + 0x58 bytes C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!MenuDemo::startCurrentDemo() Line 1526 + 0x11 bytes C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!MenuDemo::stepMenuDemo() Line 1848 C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!MenuDemo::stepDemo() Line 471 + 0xb bytes C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!hkFrameworkMain(hkDemoFrameworkOptions & options={...}, char * startUpDemo=0x02429dcc) Line 1673 + 0x13 bytes C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!main(int argc=2, char * * argvIn=0x00b323b0) Line 47 + 0x11 bytes C++
Demos_win32-net_9-0_fulldebug_multithreaded.exe!__tmainCRTStartup() Line 266 + 0x19 bytes C
Demos_win32-net_9-0_fulldebug_multithreaded.exe!mainCRTStartup() Line 182 C
kernel32.dll!76fc4911()
[Frames below may be incorrect and/or missing, no symbols loaded for kernel32.dll]
ntdll.dll!7716e4b6()
ntdll.dll!7716e489()

Once you're in the debugger after whatever is wrong breaks, you should see the call stack in the lower right hand corner of the screen. If you don't, go to Debug->Windows->Call Stack. If all you see under Debuug->Windows is "Breakpoints" "Output" and "Immediate" it means you're not running the program. Go to Debug->Start Debugging to start. Once the program breaks, you can examine the call stack to see why the program is breaking and hopefully get some idea of what's wrong. You can double click on different lines to travel to different functions up and down the call stack.

now i know what's a callstack .. but this is strange i cant debug it, maybe im doing something else wrong?
anyway this is the error i get:

Debuging information for "blitz3d.exe" canotbe found or does not match. Binary was not built with debuging information.

Do you want to continue debugging? yes/no

If i chose yes, it waits soem time (nothing apperas on the callstack) and when it opens the program then debuger exits.
What do i have to do? I also tried this way: i compiled a program that uses these custom comands i wrote, and used this exe as the debuging target, but again nothing appeared on the callstack..

It should work if you set an appropriate debugging target, but I haven't ever had to debug a DLL written for an exe I didn't personally build myself (and thus have debugging information for). By work I mean that the call stack will be garbled for the parts that are inside the exe, but you should have call stack information from the DLL you're debugging.

You're really in the dark alleys of C++ programming. Most people don't have to do this sort of debugging. I can point you to this MSDN article, and this one, but beyond that I'm afraid I'm not much help. At least not at this sort of debugging. For a project like this, I'd again like to suggest you take a look at unit testing. You should be able to add a unit testing exe to your solution which links into your DLL project and tests your functionality and can catch crashes.

Sorry I'm not much more help :/

-Jay

Still Thanks for the help and advice .. if i have some more free time il take a look at what you said ... unit testing and that article .. but irght now i have other things to do, thanks for helping, if i have some progress or i need some more help, il come back to this tread, thanks bye!

Leave a Comment

Please sign in to add a comment. Not a member? Join today