Sign in to follow this  

Visibility error

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

This topic is 2665 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this