Hello,
Ok, the issue I am having is when I create a basic sphere, and set its radius to, say, 5, only the center of the object works with dbPickObject(); it does not take into account the actual "object".
I have been trying various things and I cannot seem to get clicking on the object itself, not the center, to work.
I had some luck with vectors:
float fDistance;
dbDeleteVector3(1);
dbDeleteVector3(2);
dbDeleteVector3(3);
dbMakeVector3(1);
dbMakeVector3(2);
dbMakeVector3(3);
dbSetVector3ToCameraPosition(1, 0);
dbSetVector3
(2,
dbObjectPositionX(1),
dbObjectPositionY(1),
dbObjectPositionZ(1)
);
dbSubtractVector3(3, 1, 2);
fDistance = dbLengthVector3(3);
for(int x = 1; x < 100; x++)
{
dbSetVector3
(
2,
dbObjectPositionX(x),
dbObjectPositionY(x),
dbObjectPositionZ(x)
);
dbSubtractVector3(3, 1, 2);
dbPickScreen(dbMouseX(), dbMouseY(), fDistance);
}
dbText(0, 40, dbStr(dbGetPickVectorX() + dbXVector3(1)));
dbText(0, 50, dbStr(dbGetPickVectorY() + dbYVector3(1))); //dbCameraPositionY()));
dbText(0, 60, dbStr(dbGetPickVectorZ() + dbZVector3(1))); //dbCameraPositionZ()));
dbText(0, 70, dbStr(dbObjectPositionX(1) + dbObjectSizeX(1)));
dbText(50, 70, dbStr(dbObjectPositionX(1) - dbObjectSizeX(1)));
dbText(0, 80, dbStr(dbObjectPositionY(1) + dbObjectSizeY(1)));
dbText(50, 80, dbStr(dbObjectPositionY(1) - dbObjectSizeY(1)));
dbText(0, 90, dbStr(dbObjectPositionZ(1) + dbObjectSizeZ(1)));
dbText(50, 90, dbStr(dbObjectPositionZ(1) - dbObjectSizeZ(1)));
dbText(0, 110, dbStr(fDistance));
dbText(0, 110, dbStr(dbSQRT(fDistance)));
However, when the camera angle changes the vector calculations change and no longer function like they should.
In other words, when the sim starts, the camera is pointed at object 1 (change x for 1 if you like) and as long as the camera angle stays the same, the cursor, when the mouse is clicked, has x, y and z coords which fall inside the range of the sphere (dbObjectPositionX(1) +/- dbObjectSize(1)). This is what I need, to select an object in real world space. Now, when the camera angle changes, yet the object is still on screen, clicking inside the object no longer matches.
I feel this is due to the direction of the vectors, but I am unsure.
Anyone know an easier way, or how I may remedy my current logic?
Thanks!