I did some tests:
I wrote a function adapted from
Code: Select all
core::line3d<f32> CSceneCollisionManager::getRayFromScreenCoordinates( core::position2d<s32> pos, ICameraSceneNode* camera)
:
Code: Select all
void transform2dTo3d( core::position2d< s32 > const& pos2d, core::vector3df& pos )
{
const scene::SViewFrustum* f = camera->getViewFrustum();
core::vector3df farLeftUp = f->getFarLeftUp();
core::vector3df lefttoright = f->getFarRightUp() - farLeftUp;
core::vector3df uptodown = f->getFarLeftDown() - farLeftUp;
core::rect<s32> viewPort = driver->getViewPort();
core::dimension2d<s32> screenSize(viewPort.getWidth(), viewPort.getHeight());
f32 dx = ( pos2d.X / (f32)screenSize.Width );
f32 dy = ( pos2d.Y / (f32)screenSize.Height );
pos = f->cameraPosition + (lefttoright * (dx-0.5f)) + (uptodown * (dy-0.5f));
}
between beginFrame and endFrame:
Code: Select all
core::position2d< s32 > cursorPos = device->getCursorControl()->getPosition();
const scene::SViewFrustum* f = camera->getViewFrustum();
core::vector3df farLeftUp = f->getFarLeftUp();
core::vector3df farLeftDown = f->getFarLeftDown();
core::vector3df farRightUp = f->getFarRightUp();
core::vector3df farRightDown = f->getFarRightDown();
core::matrix4 mat;
driver->setTransform( ETS_WORLD, mat );
driver->draw3DLine( farLeftUp, farLeftDown, SColor( 255, 255, 0, 0 ) );
driver->draw3DLine( farLeftUp, farRightUp, SColor( 255, 255, 0, 0 ) );
driver->draw3DLine( farRightUp, farRightDown, SColor( 255, 255, 0, 0 ) );
driver->draw3DLine( farLeftDown, farRightDown, SColor( 255, 255, 0, 0 ) );
core::vector3df start = vector3df( 0.0f, 5.0f, 0.0f );
core::vector3df end = vector3df( 0.0f, 0.0f, 0.0f );
driver->draw3DLine( start, end );
transform2dTo3d( cursorPos, start );
driver->draw3DLine( start, end, SColor( 255, 255, 255, 0 ) );
Then after guiEnv->drawAll(); here some code:
Code: Select all
core::position2d< s32 > cursorPos = device->getCursorControl()->getPosition();
core::rect<s32> rt( cursorPos.X - 5, cursorPos.Y - 5, cursorPos.X + 5, cursorPos.Y + 5 );
driver->draw2DRectangle( video::SColor( 255, 255, 255, 255 ), rt );
And here is the result:
http://dsflake.darkstarlinux.ro/~radubo ... hess02.png
problem no1: the lines that describe the farPlane of frustum should be red ... look at the code
problem no2: only in left and bottom I can see the lines ... who knows where are the others
problem no3: the image explains all (the little white rectangle is the cursor of the mouse)
Here's how I set the camera:
Code: Select all
scene::ICameraSceneNode camera = smgr->addCameraSceneNode();
camera->setNearValue( 0.1f );
camera->setFarValue( 1000.0f );
camera->setPosition( 0.0f, 7.0f, -7.0f );
camera->setTarget( 0.0f, 2.0f, 0.0f );
So ... there are serious bugs in cameraSceneNode (I think) ... maybe the viewFrustum of the camera doesn't update properly ...