Matrix3 tm = inode->GetObjectTM(t);
float size;
int screenSize;
pblock2->GetValue(pointobj_size, t, size, FOREVER);
pblock2->GetValue(pointobj_screensize, t, screenSize, FOREVER);
float zoom = 1.0f;
if (screenSize)
zoom = vpt->GetScreenScaleFactor(tm.GetTrans())*0.005f;
if (zoom==0.0f)
zoom = 1.0f;
size *= zoom; float GetScreenScaleFactor(vector3df worldpnt,ICameraSceneNode* camera)
{
plane3df near_fplane = camera->getViewFrustum()->planes[SViewFrustum::VF_NEAR_PLANE];
vector3df cam_z = near_fplane.Normal;
vector3df width_vtr = camera->getUpVector().crossProduct(cam_z);
plane3df left_fplane = camera->getViewFrustum()->planes[SViewFrustum::VF_LEFT_PLANE];
plane3df right_fplane = camera->getViewFrustum()->planes[SViewFrustum::VF_RIGHT_PLANE];
vector3df p1,p2;
bool i1 = left_fplane.getIntersectionWithLine(worldpnt,-width_vtr,p1);
bool i2 = right_fplane.getIntersectionWithLine(worldpnt,width_vtr,p2);
return p1.getDistanceFrom(p2);
}float temp = size;
float zoom = GetScreenScaleFactor(getPosition(),SceneManager->getActiveCamera()) * 0.002f; // 0.002 is a constant scalar
if(zoom == 0.0f)
zoom = 1.0f;
temp *= zoom;
// example wireframe screen gizmo draw
for(u32 i = 0; i < edges.size(); i++)
driver->draw3DLine(verts[edges[i].X] * temp,verts[edges[i].Y] * temp,colour);float GetScreenScaleFactor(const vector3df& worldpnt,ICameraSceneNode* camera)
{
vector3df viewpnt = worldpnt;
camera->getViewMatrix().transformVect(viewpnt);
return 2 * viewpnt.Z / camera->getProjectionMatrix()[0];
}
Nothing. You check if your camera is ortho and if so, you simply return 1.0f. With ortho projection all nodes will always keep their original scales, right?Klunk wrote:my only concern would be what happens with an orthographic camera


void GetScreenCoords(const vector3df& worldpnt,ICameraSceneNode* camera, position2di& screenCoords)
{
// get the viewport
const recti& viewPort = SceneManager->getVideoDriver()->getViewPort();
// transform world point into view space
vector3df viewpnt = worldpnt;
camera->getViewMatrix().transformVect(viewpnt);
// get half the view port size at the point
float hwidth = viewpnt.Z / camera->getProjectionMatrix()[0];
float hheight = viewpnt.Z / camera->getProjectionMatrix()[5];
// get the equivalent screen coords
screenCoords.X = round32((hwidth + viewpnt.X) * viewPort.getWidth()/ hwidth * 0.5f);
screenCoords.Y = round32((hheight - viewpnt.Y) * viewPort.getHeight()/ hheight * 0.5f);
} void GetScreenCoords(const vector3df& worldpnt,ICameraSceneNode* camera, position2di& screenCoords)
{
// get the viewport size
const recti& viewPort = SceneManager->getVideoDriver()->getViewPort();
// transform world point into view space
vector3df viewpnt = worldpnt;
camera->getViewMatrix().transformVect(viewpnt);
if(viewpnt.Z == 0.0f) viewpnt.Z = FLT_EPSILON;
// get half the view port size at the point
float hwidth = camera->getProjectionMatrix()[0]/viewpnt.Z;
float hheight = camera->getProjectionMatrix()[5]/viewpnt.Z;
// get the equivalent screen coords
screenCoords.X = round32((1.0f + hwidth * viewpnt.X) * viewPort.getWidth() * 0.5f);
screenCoords.Y = round32((1.0f - hheight * viewpnt.Y) * viewPort.getHeight() * 0.5f);
}float zoom = 1.0f;
if(fixedsize)
zoom = GetScreenScaleFactor(getPosition(),SceneManager->getActiveCamera()) * screenscale;
if(zoom == 0.0f)
zoom = 1.0f;
matrix4 scalar;
scalar.setScale(zoom);
driver->setTransform(ETS_WORLD,AbsoluteTransformation * scalar);
driver->setMaterial(mbuf->setMaterial());
driver->drawMeshBuffer(mbuf);Users browsing this forum: No registered users and 1 guest