Ok, here's some code to demonstrate what I was talking about:
#include "DarkGDK.h"
#include "SC_Collision.h"
#pragma comment( lib, "SC_Collision.lib" )
//Function declaration.
int MouseOverObject( int GroupID );
//Variable for object hit.
int HitObjectID;
void DarkGDK( void )
{
dbSyncOn( ); //Set sync on so we manually handle syncing.
dbSyncRate( 60 ); //Lock framerate at 60.
dbSetDisplayMode( 1024, 768, 32 ); //Set resolution to 800 x 600.
dbSetWindowOff( ); //Set fullscreen mode on.
dbRandomize( dbTimer( ) ); //Seed random numbers.
SC_Start( ); //Start up Sparky's collision.
//We're gonna make 20 spheres and position them randomly, then set them
//up for Sparky's collision.
for ( int I = 1; I < 35; I++ )
{
dbMakeObjectSphere( I, 1.0f ); //Make our sphere.
dbPositionObject( I, dbRnd( 20 ) - 10, dbRnd( 20 ) - 10, dbRnd( 20 ) + 10 ); //Position it randomly.
SC_SetupObject( I, 1, 1 ); //Set it up: param one is object ID, two group number, and three is object type.
}
while ( LoopGDK( ) )
{
HitObjectID = MouseOverObject( 1 ); //Call our 'MouseOverFunction()' function.
if ( HitObjectID > 0 ) //If we hit an object...
{
dbText( 0, 0, dbStr( HitObjectID ) ); //Tell us the ID of the object.
dbCircle( dbObjectScreenX( HitObjectID ), dbObjectScreenY( HitObjectID ), 100 ); //Draw a circle around it.
}
dbSync( ); //Draw everything.
}
return;
}
//This function will tell us if the mouse is currently on an object.
//The only parameter is the group of the objects we want to check for.
int MouseOverObject( int GroupID )
{
//Variables for raycast.
float OldX, OldY, OldZ, NewX, NewY, NewZ;
int hit;
//Starting coordinates for our raycast will be the position of our camera.
OldX = dbCameraPositionX( );
OldY = dbCameraPositionY( );
OldZ = dbCameraPositionZ( );
//This will convert mouse coordinates to 3D coordinates.
dbPickScreen( dbMouseX( ), dbMouseY( ), 1000.0f );
NewX = OldX + dbGetPickVectorX( ); //Add the pick x value to camera position x.
NewY = OldY + dbGetPickVectorY( ); //""
NewZ = OldZ + dbGetPickVectorZ( ); //""
//Cast our ray, check for a hit with any object in group 1.
hit = SC_RayCastGroup( GroupID, OldX, OldY, OldZ, NewX, NewY, NewZ, 0 );
return hit;
}
You'll need Sparky's collision (just search it up to find the download) to compile it.
If you have any questions feel free to ask them.