Jump to content
  • Advertisement
Sign in to follow this  
Plerion

Visibility error

This topic is 2968 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

Hello!

I've got some problems with checking the visibility of a mesh in my application. Here is a video showing the problems:
">Youtube.com

Now the code is use looks like the following:

public bool IsCameraVisible
{
get
{
foreach (Adt.ADTChunk c in Chunks)
{
Vector3 pos = new Vector3(c.XBase + Utils.Metrics.Chunksize / 2.0f, c.YBase, c.ZBase + Utils.Metrics.Chunksize / 2.0f);
Vector3 dir = Mgr.Camera.Target - Mgr.Camera.Position;
float midX = pos.X;
float midZ = pos.Z;

Vector3 destV = new Vector3(midX - Mgr.Camera.Position.X, pos.Y - Mgr.Camera.Position.Y, midZ - Mgr.Camera.Position.Z);

Vector2 dir2 = new Vector2(dir.X, dir.Z);
Vector2 destV2 = new Vector2(destV.X, destV.Z);
float lengths = destV2.Length() * dir2.Length();
float skalar = dir2.X * destV2.X + /*dir.Y * destV.Y + */dir2.Y * destV2.Y;

float cos = skalar / lengths;
float angle = (float)Math.Acos((double)cos);
float angleD = (angle * 180) / (float)Math.PI;
if (angleD > 60 || (destV.Length() > 1.4f * Utils.Metrics.Tilesize))
continue;
return true;
}
return false;
}
}
}



Some explanation:
I use atlases of textures to reduce render calls. To determine if a certain atlas (that is made up of 16 chunks) is visible to the camera the above code looks if any of the chunks is visible and returns it. The code basically works well if i don't render the atlases but every chunks as an own mesh. But in the atlas the strange behavior shown in the video comes up! Im clueless why this happens...

Greetings
Plerion

Share this post


Link to post
Share on other sites
Advertisement
When looking again on the video it seems for me like the culling is done somehow inverted. Like the whole thing is mirrored. Could that result from the code posted or do you think something is wrong with my coordinates?

Share this post


Link to post
Share on other sites
Arw, stupid error is annoying...

foreach (TextureAtlas tex in Atlasses)
{
if (!tex.IsCameraVisible)
continue;



should've been

foreach (TextureAtlas tex in Atlasses)
{
if (!tex.IsCameraVisible)
{
++i;
continue;
}

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!