Visibility error

Started by
1 comment, last by Plerion 13 years, 7 months ago
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
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?
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;    }

This topic is closed to new replies.

Advertisement