dbPickScreen will calculate 3D vector coordinates relative to the camera position based on the 2D overlay. This is great for determining where in the 3D world your mouse cursor (a 2D world object) is positioned. The following example shows you how to align a 3D world object "target.x" aka OBJECT_TARGETBOX to the 2D coordinates of your mouse cursor.

You can use other features such as dbIntersectObject() to achieve a similar technique, but instead based on the surface of an object (terrain, model, etc.)

WARNING: using dbSetCameraRange() can cause the dbPickScreen() method to stop working if your near range is 0 and/or far range is incredibly high!

Example Code:

//DARK GDK Main.cpp file:

#include "DarkGDK.h"

void DarkGDK ( void )
	dbSyncOn   ( );
	dbSyncRate ( 60 );//Activa la sincronisacion del juego o por frames de imagenes por segundo
	// Set the working directory.
	dbSetDisplayMode(1024,768,32);// aqui la configuracion de pantalla o resolucion Colocar menu opciones cambiar la resolucion
        dbLoadObject( "Mapas/map1.x", OBJECT_TARGETBOX ); //load .X file (use your own for this - if you don't have a model file this will not work!)

        dbPositionCamera ( 642.0f, 254.0f, 271.0f ); //position camera at some point in space

        dbRotateCamera ( 45.0f, 0.0f, 0.0f );

        while ( LoopGDK ( ) )

                dbPickScreen(dbMouseX(), dbMouseY(), 100); //get mouse coordinates in 2D screen - distance example of 100
                float(vx) = dbGetPickVectorX();
                float(vy) = dbGetPickVectorY();
                float(vz) = dbGetPickVectorZ();
                float(camx) = dbCameraPositionX();
                float(camy) = dbCameraPositionY();
                float(camz) = dbCameraPositionZ();
                float(mult) = dbABS(camy/vy);
                vx = vx*mult+camx;  //convert to 3D World X coordinates
                vy = vy*mult+camy;  //convert to 3D World Y coordinates
                vz = vz*mult+camz;  //convert to 3D World Z coordinates

                //position the "target.x" model file at the 3D coordinates relative to the mouse cursor in the 2D overlay
                dbPositionObject(OBJECT_TARGETBOX, vx, vy, vz);

Ad blocker interference detected!

Wikia is a free-to-use site that makes money from advertising. We have a modified experience for viewers using ad blockers

Wikia is not accessible if you’ve made further modifications. Remove the custom ad blocker rule(s) and the page will load as expected.