Jump to content
  • Advertisement
Sign in to follow this  
Ranger_One

3d sphere coord in 2d

This topic is 4857 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok, I need to project a point on a 3d sphere in a 2d view. Here is the information I have: Bearing & Mark (in degrees) and Radius. Now, I could figure out the location in 3d space (X,Y,Z) and then make a projection matrix to project that onto a 2d surface. I understand all that. What I'm asking here is a simpler way to handle it, since the camera is fixed in this case- straight on the sphere. Is there a simpler way to handle this scenario? Thanks

Share this post


Link to post
Share on other sites
Advertisement
Don't know if it is simpler but you could fire a ray from the camera through the point and find the point of intersection with your 2D surface (plane).

This is pretty straightforward and probably cheaper than setting up a matrix and performing a projection.

Just an idea...

Regards!
/hObbE

Share this post


Link to post
Share on other sites
You can project a sphere to screen coordinates using w for calcule radius.
I've got a code from my engine. Let's see:



bool GLeonCamera::ProjectSphere(GLEON_VECTOR3 * origin, GLEON_REAL radius, GLEON_VECTOR3 * projorigin, GLEON_REAL &projradius)
{
GLEON_VECTOR3 vtemp;
GLEON_VECTOR4 v4temp,v4temp2;
GLEON_VECTOR4 cameraplane;


GLEON_REAL rtemp;


GetFrustumPlane(CONSTGLEON_FRUSTUMBACK,&cameraplane);

/////if sphere lie behind of the near plane, don't apply perspective //////transformation
rtemp = GLeonMath::DistancePlanePoint(&cameraplane,origin);
if(GLeonMath::IsNegative(rtemp)==false)
{
GLeonMath::Matrix4TransformVec3(
&vtemp,
origin,
&m_world_to_camera);

projorigin->x = (1.0f + vtemp.x)*0.5f;
projorigin->y = -(1.0f + vtemp.y)*0.5f;
projorigin->z = vtemp.z;
projradius = radius;
return true;
}
///////but if sphere is visible, then apply perspective transformation



v4temp.x = origin->x;
v4temp.y = origin->y;
v4temp.z = origin->z;
v4temp.w = 1.0f;

///project point
////total transform is m_matProjection*m_world_to_camera GLeonMath::Matrix4TransformVec4(
&v4temp2,
&v4temp,
&m_totaltransform);

if(GLeonMath::IsZero(v4temp2.w))
{
return false;////invalid value
}


projorigin->x = (1.0f + v4temp2.x/v4temp2.w)*0.5f;///scale with W
projorigin->y = (1.0f + v4temp2.y/v4temp2.w)*0.5f;///scale with W
projorigin->z = m_ScissorN+ -rtemp;///ScissorN is the near plane
///distance
projradius = radius/v4temp2.w;///scale with W

return true;
///returns a point that x lies in range [0,1]
/// y lies in range [0,1] with y axis pointing down( text direction)
//// and z lies in range [m_frustumN,m_frustumF]
}




I hope that it help you.

Share this post


Link to post
Share on other sites
Illco, ok I can see that. Basically I'm using 2 polar systems in conjunction, one for mark and one for bearing. Hmmmm.

Ok, so now my head explodes on how to combine 2 of them to describe any point on the surface of a sphere...

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!