Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / collision help

Author
Message
manuel31
15
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 9th Feb 2009 21:57
i make a 3ds max model and convert it to dbo, when i execute i can see my model but the camara pass through the model how can i add the collision.
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 10th Feb 2009 11:35
Make a invisible object and set it to the camera position. Now you can add collision by using Sparky's collision or DarkGDK's built-in collision system.
andiconda
15
Years of Service
User Offline
Joined: 10th Feb 2009
Location:
Posted: 10th Feb 2009 18:50
just a note i'm not big into posting code examples, because its more of learning experience if you code it.
so i give help in the form of algorithms or instructions

well if its a dbo and you can treat it as an object
so first of all set collision status to it (make sure to use the object id number)
then make sure to turn on automaticobjectcollision for the camera
(i forget the actual lines of code for it, but you have a manual for that.)
now you can set the response value to "1", which will move the camera back to the last collision free zone.
i find this to be a little buggy on complex enviroments, but it might work fine for a small test.
personally i make a function to handle the collision
the basic algorithm would go as follows

check collision on x

find out which direction (if its negative its on the left side
camera positive on the right side)

if collision value is greater than collision tolerence (you decide how close you want it to get)

move camera back equal to the collision value

now this template can be recycled for z and y
though y, if you plan on doing gravity, will require extra exceptions and overall be slightly more complex

another thing i found when i was doing bsp collision, is that to get rid of studders you would say
check horizontal collision
process
check vertical collision
process
sync
manuel31
15
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 12th Feb 2009 00:45
Please, can you check this code, and tell me what is wrong with it?, If you test it will be better, I can't find why I still can't collide with universe.dbo sample that have dark gdk tutorial

PLEASE HELP!

#include "DarkGDK.h"

// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );

// switch to the media directory, load our world
// and turn lighting off
SetCurrentDirectory ( "media" );
dbLoadObject( "universe.dbo", 1 );
dbSetObjectLight( 1, 0 );
dbPositionObject( 1 , dbCameraPositionX (434 ) , dbCameraPositionY ( 42 ) , dbCameraPositionZ( -517) );
dbSetObjectCollisionOn(1);

dbMakeObjectCube(202,10);
dbHideObject(202);


// load a model for our sky
dbLoadObject( "skybox2.x", 2 );
dbSetObjectLight( 2, 0 );
dbSetObjectTexture( 2, 3, 2 );
dbScaleObject( 2, 5000, 5000, 5000 );


// position the camera
dbPositionCamera( 434, 42, -517 );

// camera variables
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;

int map_collision=0;


// our main loop

while ( LoopGDK ( ) )
{
dbSetObjectToCameraOrientation ( 202);


dbPositionObject( 202 , dbCameraPositionX ( 0 ) , dbCameraPositionY ( 0) , dbCameraPositionZ( 0 ) );

//Collision
if (dbObjectCollision(202,1)==1)
/* change the second number for the object you want to collide with or 0 for all objects*/
{

map_collision=1;
}
else
{
dbAutomaticObjectCollision ( 1, 1.0f, 1 );
}

// move the camera using the arrow keys
dbControlCameraUsingArrowKeys ( 0, 3.0f, 3.0f );

// create a rotation axis based on mouse movement
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );

// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );


// update the screen
dbSync ( );
}

// return back to windows
return;
}

THANKS IN ADVANCE!!!
CheatCat
17
Years of Service
User Offline
Joined: 7th Mar 2007
Location: Sweden
Posted: 12th Feb 2009 08:52
You should only use dbAutomaticObjectCollision() one time and not in a loop.
Then you set the map_collision value, but you never check it. You should move back the camera when you hit something. Do something like this:
manuel31
15
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 12th Feb 2009 15:28
Hey CheatCat, thanks for your help, see, im new with this (dark gdk), so I will need more of a dummy explanation, because still i can't make it work...

I got this question:

2.- The code you gave me, should be inside the main loop? or global?

I got this now, can you check it please?

--------------------------------------------------

SetCurrentDirectory ( "media" );
dbLoadObject( "universe.dbo", 1 );
dbSetObjectLight( 1, 0 );
dbPositionObject( 1 , dbCameraPositionX (434 ) , dbCameraPositionY ( 42 ) , dbCameraPositionZ( -517) );
dbAutomaticObjectCollision (1, 0.0f, 1 );

dbMakeObjectCube(202,10);
dbHideObject(202);


// load a model for our sky
dbLoadObject( "skybox2.x", 2 );
dbSetObjectLight( 2, 0 );
dbSetObjectTexture( 2, 3, 2 );
dbScaleObject( 2, 5000, 5000, 5000 );


// position the camera
dbPositionCamera( 434, 42, -517 );

// camera variables
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;

int map_collision=0;
float ox = dbObjectPositionX(202), oy = dbObjectPositionY(202), oz = dbObjectPositionZ(202);


// our main loop

while ( LoopGDK ( ) )
{
dbSetObjectToCameraOrientation ( 202);
dbPositionObject( 202 , dbCameraPositionX ( 0 ) , dbCameraPositionY ( 0) , dbCameraPositionZ( 0 ) );


//Collision
if(map_collision > 0)
{
dbPositionCamera(0, ox, oy, oz);
map_collision = 0;
}

--------------------------------------------------

STILL NO COLLISION!!

thanks!!!
andiconda
15
Years of Service
User Offline
Joined: 10th Feb 2009
Location:
Posted: 14th Feb 2009 05:22
sorry i kinda slaughtered your code
first of collision doesn't happen by itself unless you use automatic camera collision, but its sticky
i used it here to give a crude example of working collision
off make sure to set the skybox collision off
for whatever reason that is causing collision

experiment with the dbGetCollisionX() *also comes in Y and Z*
to find what you like best.
if you want an fps camera collision is the best way to go
if it is third person then use an object collision
never use an object as a collision box, collision boxes are provided and will conflict.
i'm kinda sleepy so i didn't go to in depth if you have more questions i can see if i can throw together a snippet of my own video game's collision system (for bsp)


// Dark GDK - The Game Creators - www.thegamecreators.com

// the wizard has created a very simple 3D project that uses Dark GDK
// it can be used as a starting point in making your own 3D games

// whenever using Dark GDK you must ensure you include the header file
#include "DarkGDK.h"
// the main entry point for the application is this function
void DarkGDK ( void )
{
// turn on sync rate and set maximum rate to 60 fps
dbSyncOn ( );
dbSyncRate ( 60 );

// switch to the media directory, load our world
// and turn lighting off
SetCurrentDirectory ( "media" );
dbLoadObject( "universe.dbo", 1 );
dbSetObjectLight( 1, 0 );
dbPositionObject( 1 , dbCameraPositionX (434 ) , dbCameraPositionY ( 42 ) , dbCameraPositionZ( -517) );
dbSetObjectCollisionToPolygons(1);


// load a model for our sky
dbLoadObject( "skybox2.x", 2 );
dbSetObjectLight( 2, 0 );
dbSetObjectTexture( 2, 3, 2 );
dbScaleObject( 2, 5000, 5000, 5000 );
dbSetObjectCollisionOff(2);


// position the camera
dbPositionCamera( 434, 42, -517 );
dbAutomaticCameraCollision(0,10,0);

// camera variables
float fCameraAngleX = 0.0f;
float fCameraAngleY = 0.0f;

int map_collision=0;


// our main loop

while ( LoopGDK ( ) )
{


// move the camera using the arrow keys
dbControlCameraUsingArrowKeys ( 0, 3.0f, 3.0f );

// create a rotation axis based on mouse movement
fCameraAngleX = dbWrapValue ( fCameraAngleX + dbMouseMoveY ( ) * 0.4f );
fCameraAngleY = dbWrapValue ( fCameraAngleY + dbMouseMoveX ( ) * 0.4f );

// rotate camera
dbXRotateCamera ( fCameraAngleX );
dbYRotateCamera ( fCameraAngleY );

// update the screen
dbSync ( );
}

// return back to windows
return;
}
manuel31
15
Years of Service
User Offline
Joined: 9th Jan 2009
Location:
Posted: 14th Feb 2009 15:39
PERFECT!!!!!!!!!!!!!!!!!

That's what I needed andiconda!!! Completely grateful for your response.

It was more easy than I expected...I can notice because you took out some useless code I had.

And yes!!, It would be great if you provide me a snippet of your video game collision system, I'll like to check it!

I only got 1 question, How can I stop the camera moving "freely" inside the universe.dbo world?, I mean, I don't want the camera to "fly away" and levitate outside the world, I think this is called "gravity", is there a function that can help me through this? And feel like I'm stepping the floor?

And Thanks in Advance!

Login to post a reply

Server time is: 2024-09-30 17:36:44
Your offset time is: 2024-09-30 17:36:44