Exemple #1
0
 /// <summary>Resets the renderer to the default state</summary>
 public static void Reset()
 {
     Objects                               = new RendererObject[256];
     ObjectCount                           = 0;
     StaticOpaque                          = new ObjectGroup[] { };
     DynamicOpaque                         = new ObjectList();
     DynamicAlpha                          = new ObjectList();
     OverlayOpaque                         = new ObjectList();
     OverlayAlpha                          = new ObjectList();
     OptionLighting                        = true;
     OptionAmbientColor                    = new Color24(160, 160, 160);
     OptionDiffuseColor                    = new Color24(160, 160, 160);
     OptionLightPosition                   = new Vector3(0.215920077052065f, 0.875724044222352f, -0.431840154104129f);
     OptionLightingResultingAmount         = 1.0f;
     GL.Disable(EnableCap.Fog); FogEnabled = false;
 }
Exemple #2
0
 /// <summary>Re-adds all objects within the world, for example after a screen resolution change</summary>
 public static void ReAddObjects()
 {
     RendererObject[] list = new RendererObject[ObjectCount];
     for (int i = 0; i < ObjectCount; i++)
     {
         list[i] = Objects[i];
     }
     for (int i = 0; i < list.Length; i++)
     {
         HideObject(ref list[i].InternalObject);
     }
     for (int i = 0; i < list.Length; i++)
     {
         ShowObject(list[i].InternalObject, list[i].Type);
     }
 }
Exemple #3
0
        /// <summary>Makes an object visible within the world</summary>
        /// <param name="objectToShow">The object to show</param>
        /// <param name="Type">Whether this is a static or dynamic object</param>
        public static void ShowObject(StaticObject objectToShow, ObjectType Type)
        {
            if (objectToShow == null)
            {
                return;
            }
            if (objectToShow.RendererIndex == 0)
            {
                if (ObjectCount >= Objects.Length)
                {
                    Array.Resize <RendererObject>(ref Objects, Objects.Length << 1);
                }

                Objects[ObjectCount] = new RendererObject(objectToShow, Type);
                int f = objectToShow.Mesh.Faces.Length;
                Objects[ObjectCount].FaceListReferences = new ObjectListReference[f];
                for (int i = 0; i < f; i++)
                {
                    bool alpha = false;
                    int  k     = objectToShow.Mesh.Faces[i].Material;
                    OpenGlTextureWrapMode wrap = OpenGlTextureWrapMode.ClampClamp;
                    if (objectToShow.Mesh.Materials[k].DaytimeTexture != null | objectToShow.Mesh.Materials[k].NighttimeTexture != null)
                    {
                        if (objectToShow.Mesh.Materials[k].WrapMode == null)
                        {
                            // If the object does not have a stored wrapping mode, determine it now
                            for (int v = 0; v < objectToShow.Mesh.Vertices.Length; v++)
                            {
                                if (objectToShow.Mesh.Vertices[v].TextureCoordinates.X <0.0f |
                                                                                        objectToShow.Mesh.Vertices[v].TextureCoordinates.X> 1.0f)
                                {
                                    wrap |= OpenGlTextureWrapMode.RepeatClamp;
                                }
                                if (objectToShow.Mesh.Vertices[v].TextureCoordinates.Y <0.0f |
                                                                                        objectToShow.Mesh.Vertices[v].TextureCoordinates.Y> 1.0f)
                                {
                                    wrap |= OpenGlTextureWrapMode.ClampRepeat;
                                }
                            }
                        }
                        else
                        {
                            //Yuck cast, but we need the null, as otherwise requires rewriting the texture indexer
                            wrap = (OpenGlTextureWrapMode)objectToShow.Mesh.Materials[k].WrapMode;
                        }
                        if (objectToShow.Mesh.Materials[k].DaytimeTexture != null)
                        {
                            if (currentHost.LoadTexture(objectToShow.Mesh.Materials[k].DaytimeTexture, wrap))
                            {
                                TextureTransparencyType type =
                                    objectToShow.Mesh.Materials[k].DaytimeTexture.Transparency;
                                if (type == TextureTransparencyType.Alpha)
                                {
                                    alpha = true;
                                }
                                else if (type == TextureTransparencyType.Partial && currentOptions.TransparencyMode == TransparencyMode.Quality)
                                {
                                    alpha = true;
                                }
                            }
                        }
                        if (objectToShow.Mesh.Materials[k].NighttimeTexture != null)
                        {
                            if (currentHost.LoadTexture(objectToShow.Mesh.Materials[k].NighttimeTexture, wrap))
                            {
                                TextureTransparencyType type =
                                    objectToShow.Mesh.Materials[k].NighttimeTexture.Transparency;
                                if (type == TextureTransparencyType.Alpha)
                                {
                                    alpha = true;
                                }
                                else if (type == TextureTransparencyType.Partial & currentOptions.TransparencyMode == TransparencyMode.Quality)
                                {
                                    alpha = true;
                                }
                            }
                        }
                    }
                    if (Type == ObjectType.Overlay & CameraProperties.Camera.CurrentRestriction != CameraRestrictionMode.NotAvailable)
                    {
                        alpha = true;
                    }
                    else if (objectToShow.Mesh.Materials[k].Color.A != 255)
                    {
                        alpha = true;
                    }
                    else if (objectToShow.Mesh.Materials[k].BlendMode == MeshMaterialBlendMode.Additive)
                    {
                        alpha = true;
                    }
                    else if (objectToShow.Mesh.Materials[k].GlowAttenuationData != 0)
                    {
                        alpha = true;
                    }
                    ObjectListType listType;
                    switch (Type)
                    {
                    case ObjectType.Static:
                        listType = alpha ? ObjectListType.DynamicAlpha : ObjectListType.StaticOpaque;
                        break;

                    case ObjectType.Dynamic:
                        listType = alpha ? ObjectListType.DynamicAlpha : ObjectListType.DynamicOpaque;
                        break;

                    case ObjectType.Overlay:
                        listType = alpha ? ObjectListType.OverlayAlpha : ObjectListType.OverlayOpaque;
                        break;

                    default:
                        throw new InvalidOperationException();
                    }
                    if (listType == ObjectListType.StaticOpaque)
                    {
                        /*
                         * For the static opaque list, insert the face into
                         * the first vacant position in the matching group's list.
                         * */
                        int groupIndex = (int)objectToShow.GroupIndex;
                        if (groupIndex >= StaticOpaque.Length)
                        {
                            if (StaticOpaque.Length == 0)
                            {
                                StaticOpaque = new ObjectGroup[16];
                            }
                            while (groupIndex >= StaticOpaque.Length)
                            {
                                Array.Resize <ObjectGroup>(ref StaticOpaque, StaticOpaque.Length << 1);
                            }
                        }
                        if (StaticOpaque[groupIndex] == null)
                        {
                            StaticOpaque[groupIndex] = new ObjectGroup();
                        }
                        ObjectList list     = StaticOpaque[groupIndex].List;
                        int        newIndex = list.FaceCount;
                        for (int j = 0; j < list.FaceCount; j++)
                        {
                            if (list.Faces[j] == null)
                            {
                                newIndex = j;
                                break;
                            }
                        }
                        if (newIndex == list.FaceCount)
                        {
                            if (list.FaceCount == list.Faces.Length)
                            {
                                Array.Resize <ObjectFace>(ref list.Faces, list.Faces.Length << 1);
                            }
                            list.FaceCount++;
                        }
                        list.Faces[newIndex] = new ObjectFace
                        {
                            ObjectListIndex = ObjectCount,
                            ObjectReference = objectToShow,
                            FaceIndex       = i,
                            Wrap            = wrap
                        };

                        // HACK: Let's store the wrapping mode.

                        StaticOpaque[groupIndex].Update            = true;
                        Objects[ObjectCount].FaceListReferences[i] = new ObjectListReference(listType, newIndex);
                        InfoStaticOpaqueFaceCount++;

                        /*
                         * Check if the given object has a bounding box, and insert it to the end of the list of bounding boxes if required
                         */
                        if (objectToShow.Mesh.BoundingBox != null)
                        {
                            int Index = list.BoundingBoxes.Length;
                            for (int j = 0; j < list.BoundingBoxes.Length; j++)
                            {
                                if (list.Faces[j] == null)
                                {
                                    Index = j;
                                    break;
                                }
                            }
                            if (Index == list.BoundingBoxes.Length)
                            {
                                Array.Resize <BoundingBox>(ref list.BoundingBoxes, list.BoundingBoxes.Length << 1);
                            }
                            list.BoundingBoxes[Index].Upper = objectToShow.Mesh.BoundingBox[0];
                            list.BoundingBoxes[Index].Lower = objectToShow.Mesh.BoundingBox[1];
                        }
                    }
                    else
                    {
                        /*
                         * For all other lists, insert the face at the end of the list.
                         * */
                        ObjectList list;
                        switch (listType)
                        {
                        case ObjectListType.DynamicOpaque:
                            list = DynamicOpaque;
                            break;

                        case ObjectListType.DynamicAlpha:
                            list = DynamicAlpha;
                            break;

                        case ObjectListType.OverlayOpaque:
                            list = OverlayOpaque;
                            break;

                        case ObjectListType.OverlayAlpha:
                            list = OverlayAlpha;
                            break;

                        default:
                            throw new InvalidOperationException();
                        }
                        if (list.FaceCount == list.Faces.Length)
                        {
                            Array.Resize <ObjectFace>(ref list.Faces, list.Faces.Length << 1);
                        }
                        list.Faces[list.FaceCount] = new ObjectFace
                        {
                            ObjectListIndex = ObjectCount,
                            ObjectReference = objectToShow,
                            FaceIndex       = i,
                            Wrap            = wrap
                        };

                        // HACK: Let's store the wrapping mode.

                        Objects[ObjectCount].FaceListReferences[i] = new ObjectListReference(listType, list.FaceCount);
                        list.FaceCount++;
                    }
                }
                objectToShow.RendererIndex = ObjectCount + 1;
                ObjectCount++;
            }
        }