Ok, to place an object in 3D space, you need to do so in relation to another object if you want to do it with a mouse click...
you get what are known as Pick Vectors.. here is an example of creating an object and placing it where the mouse is clicked on a large plain.
Here is a complete example program for you, just copy paste it into a new empty DarkGDK Game project and it will run.
#include "DarkGDK.h"
float cr, cf, ncr, ncf, cx, cy, ncx, ncy;
float fTargetX, fTargetY, fTargetZ;
void DarkGDK()
{
dbSyncOn();
dbSyncRate(0);
//dbAutoCamOff();
//dbSetCameraRange(0.1, 50000);
//dbBackdropOn();
//dbSetAmbientLight(70);
// This object is the "ground"
dbMakeObjectBox(1, 3500, 1.0, 3500);
dbColorObject(1, dbRGB(0, 155, 0));
dbSetObjectAmbient(1, 0 );
// this object is the one being placed
dbMakeObjectCube(2, 50.0);
dbColorObject(2, dbRGB(255, 0, 0));
dbSetObjectAmbient(2, 0);
// this will position our camera above the "ground"
dbPositionCamera(0, 250, 0);
while(LoopGDK())
{
// this will place the cube object at the XYZ coords of a mouse click.
if(dbMouseClick() == 1)
{
// this line tells the GDK to store some info about which 3d object your
// mouse is over
int iNull = dbPickObject(dbMouseX(), dbMouseY(), 1, 1);
// these 3 lines store a 3d world postiion in some variables, the commands
// dbGetPickVector, contain data that was gathered when dbPickObject was called.
fTargetX = dbCameraPositionX() + dbGetPickVectorX();
fTargetY = dbCameraPositionY() + dbGetPickVectorY();
fTargetZ = dbCameraPositionZ() + dbGetPickVectorZ();
// this will position the cube, NOTE : the +25.0 on the Y component
// that is half the value of the cube's height, as the cube's 0, 0, 0 position
// places it halfway through the "ground"
dbPositionObject(2, fTargetX, fTargetY+25.0, fTargetZ);
}
////////////////////////////////////////////////////////
// This is just for camera movement. It is not important
if(dbRightKey() || dbKeyState(32)) cr = -5;
if(dbLeftKey() || dbKeyState(30)) cr = 5;
if(dbUpKey() || dbKeyState(17)) cf = 5;
if(dbDownKey() || dbKeyState(31)) cf = -5;
if(dbShiftKey())
{
ncr = dbCurveValue(cr, ncr, 10);
ncf = dbCurveValue(cf+20, ncf+20, 10);
}
ncr = dbCurveValue(cr, ncr, 5);
ncf = dbCurveValue(cf, ncf, 5);
cx += dbMouseMoveY()*0.2;
cy += dbMouseMoveX()*0.2;
if(cx > 80) cx = 80;
if(cx < -80) cx = -80;
ncx = dbCurveAngle(cx, ncx, 2);
ncy = dbCurveAngle(cy, ncy, 2);
dbMoveCamera(ncf);
dbRotateCamera(0, dbWrapValue(ncy - 90), 0);
dbMoveCamera(ncr);
dbRotateCamera(0, dbWrapValue(ncy + 90), 0);
dbRotateCamera(ncx, ncy, 0);
cr=0; cf = 0;
dbText(0, 0, "Left Click on the Green surface to place the Red Cube");
// update the screen
dbSync();
}
return;
}
If it ain't broke.... DONT FIX IT !!!