/// <summary>
 /// Create the animation. The passed animation block is expected
 /// to contain a defintion of a fixed rotation. If not, bad things will happen.
 /// </summary>
 /// <param name="anim">The IAnimation block with the info.</param>
 /// <param name="id">localID to lookup the prim in the RegionRenderInfo.renderPrimList</param>
 public AnimatPosition(OMV.Vector3 newPos, float durationSeconds, RegionRenderInfo rri, uint id)
     : base(AnimatBase.AnimatTypePosition)
 {
     m_infoID = id;
     RenderablePrim rp = rri.renderPrimList[id];
     m_origionalPosition = rp.Position;
     m_targetPosition = newPos;
     m_durationSeconds = durationSeconds;
     m_distanceVector = m_targetPosition - m_origionalPosition;
     m_progress = 0f;
 }
 /// <summary>
 /// Called for each frame. Advance the rotation.
 /// </summary>
 /// <param name="timeSinceLastFrame">seconds since last frame display</param>
 /// <param name="rri">RegionRenderInfo for region the animation is in</param>
 /// <returns>true to say we never exit</returns>
 public override bool Process(float timeSinceLastFrame, RegionRenderInfo rri)
 {
     float nextStep = m_rotationsPerSecond * timeSinceLastFrame;
     float nextIncrement = Constants.TWOPI * nextStep;
     while (nextIncrement > Constants.TWOPI) nextIncrement -= Constants.TWOPI;
     OMV.Quaternion newRotation = OMV.Quaternion.CreateFromAxisAngle(m_rotationAxis, nextIncrement);
     lock (rri) {
         try {
             RenderablePrim rp = rri.renderPrimList[m_infoID];
             rp.Rotation = newRotation * rp.Rotation;
         }
         catch (Exception e) {
             LogManager.Log.Log(LogLevel.DBADERROR, "Did not find prim for FixedRotation: {0}", e);
         }
     }
     return true;        // we never exit
 }
 /// <summary>
 /// Called for each frame. Advance the position.
 /// </summary>
 /// <param name="timeSinceLastFrame">seconds since last frame display</param>
 /// <param name="rri">RegionRenderInfo for region the animation is in</param>
 /// <returns>true to say we never exit</returns>
 public override bool Process(float timeSinceLastFrame, RegionRenderInfo rri)
 {
     bool ret = true;
     float thisProgress = timeSinceLastFrame / m_durationSeconds;
     m_progress += thisProgress;
     RenderablePrim rp = rri.renderPrimList[m_infoID];
     if (m_progress >= 1f) {
         // if progressed all the way, we're at the destination
         rp.Position = m_targetPosition;
         ret = false;    // we're done animating
     }
     else {
         // only part way there
         rp.Position = m_origionalPosition + m_distanceVector * m_progress;
     }
     return ret;
 }
Пример #4
0
 /// <summary>
 /// Loop through the list of animations for this region and call their "Process" routines
 /// </summary>
 /// <param name="timeSinceLastFrame">seconds since list frame</param>
 /// <param name="rri">RegionRenderInfo for the region</param>
 public static void ProcessAnimations(float timeSinceLastFrame, RegionRenderInfo rri)
 {
     lock (rri) {
         List<AnimatBase> removeAnimations = new List<AnimatBase>();
         foreach (AnimatBase ab in rri.animations) {
             try {
                 if (!ab.Process(timeSinceLastFrame, rri)) {
                     removeAnimations.Add(ab);   // remember so we can remove later
                 }
             }
             catch {
             }
         }
         // since we can't remove animations while interating the list, do it now
         foreach (AnimatBase ab in removeAnimations) {
             rri.animations.Remove(ab);
         }
     }
 }
Пример #5
0
        private void UpdateRegionTerrainMesh(RegionContextBase rcontext, RegionRenderInfo rri)
        {
            TerrainInfoBase ti = rcontext.TerrainInfo;
            rri.terrainVertices = new float[3 * ti.HeightMapLength * ti.HeightMapWidth];
            rri.terrainTexCoord = new float[2 * ti.HeightMapLength * ti.HeightMapWidth];
            rri.terrainNormal = new float[3 * ti.HeightMapLength * ti.HeightMapWidth];
            int nextVert = 0;
            int nextTex = 0;
            int nextNorm = 0;
            for (int xx=0; xx < ti.HeightMapLength; xx++) {
            for (int yy = 0; yy < ti.HeightMapWidth; yy++ ) {
                rri.terrainVertices[nextVert + 0] = (float)xx / ti.HeightMapLength * rcontext.Size.X;
                rri.terrainVertices[nextVert + 1] = (float)yy / ti.HeightMapWidth * rcontext.Size.Y;
                rri.terrainVertices[nextVert + 2] = ti.HeightMap[xx, yy];
                nextVert += 3;
                rri.terrainTexCoord[nextTex + 0] = xx / ti.HeightMapLength;
                rri.terrainTexCoord[nextTex + 1] = yy / ti.HeightMapWidth;
                nextTex += 2;
                rri.terrainNormal[nextNorm + 0] = 0f;   // simple normal pointing up
                rri.terrainNormal[nextNorm + 1] = 1f;
                rri.terrainNormal[nextNorm + 2] = 0f;
                nextNorm += 3;
            }
            }
            // Create the quads which make up the terrain
            rri.terrainIndices = new UInt16[4 * ti.HeightMapLength * ti.HeightMapWidth];
            int nextInd = 0;
            for (int xx=0; xx < ti.HeightMapLength-1; xx++) {
            for (int yy = 0; yy < ti.HeightMapWidth-1; yy++ ) {
                rri.terrainIndices[nextInd + 0] = (UInt16)((yy + 0) + (xx + 0)* ti.HeightMapLength);
                rri.terrainIndices[nextInd + 1] = (UInt16)((yy + 1) + (xx + 0)* ti.HeightMapLength);
                rri.terrainIndices[nextInd + 2] = (UInt16)((yy + 1) + (xx + 1)* ti.HeightMapLength);
                rri.terrainIndices[nextInd + 3] = (UInt16)((yy + 0) + (xx + 1)* ti.HeightMapLength);
                nextInd += 4;
            }
            }
            rri.terrainWidth = ti.HeightMapWidth;
            rri.terrainLength = ti.HeightMapLength;

            // Calculate normals
            // Take three corners of each quad and calculate the normal for the vector
            //   a--b--e--...
            //   |  |  |
            //   d--c--h--...
            // The triangle a-b-d calculates the normal for a, etc
            int nextQuad = 0;
            int nextNrm = 0;
            for (int xx=0; xx < ti.HeightMapLength-1; xx++) {
            for (int yy = 0; yy < ti.HeightMapWidth-1; yy++ ) {
                OMV.Vector3 aa, bb, cc;
                int offset = rri.terrainIndices[nextQuad + 0] * 3;
                aa.X = rri.terrainVertices[offset + 0];
                aa.Y = rri.terrainVertices[offset + 1];
                aa.Z = rri.terrainVertices[offset + 2];
                offset = rri.terrainIndices[nextQuad + 1] * 3;
                bb.X = rri.terrainVertices[offset + 0];
                bb.Y = rri.terrainVertices[offset + 1];
                bb.Z = rri.terrainVertices[offset + 2];
                offset = rri.terrainIndices[nextQuad + 3] * 3;
                cc.X = rri.terrainVertices[offset + 0];
                cc.Y = rri.terrainVertices[offset + 1];
                cc.Z = rri.terrainVertices[offset + 2];
                OMV.Vector3 mm = aa - bb;
                OMV.Vector3 nn = aa - cc;
                OMV.Vector3 theNormal = -OMV.Vector3.Cross(mm, nn);
                theNormal.Normalize();
                rri.terrainNormal[nextNrm + 0] = theNormal.X;   // simple normal pointing up
                rri.terrainNormal[nextNrm + 1] = theNormal.Y;
                rri.terrainNormal[nextNrm + 2] = theNormal.Z;
                nextNrm += 3;
                nextQuad += 4;
            }
            rri.terrainNormal[nextNrm + 0] = 1.0f;
            rri.terrainNormal[nextNrm + 1] = 0.0f;
            rri.terrainNormal[nextNrm + 2] = 0.0f;
            nextNrm += 3;
            }
        }
Пример #6
0
        private void RenderTerrain(RegionContextBase rcontext, RegionRenderInfo rri)
        {
            GL.PushMatrix();

            // if the terrain has changed,
            if (rri.refreshTerrain) {
            rri.refreshTerrain = false;
            UpdateRegionTerrainMesh(rcontext, rri);
            }

            // apply region offset
            GL.MultMatrix(Math3D.CreateTranslationMatrix(CalcRegionOffset(rcontext)));

            // everything built. Display the terrain
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.NormalArray);

            GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, rri.terrainTexCoord);
            GL.VertexPointer(3, VertexPointerType.Float, 0, rri.terrainVertices);
            GL.NormalPointer(NormalPointerType.Float, 0, rri.terrainNormal);
            GL.DrawElements(BeginMode.Quads, rri.terrainIndices.Length, DrawElementsType.UnsignedShort, rri.terrainIndices);

            GL.PopMatrix();
        }
Пример #7
0
        //int[] CubeMapDefines = new int[]
        //{
        //    Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB,
        //    Gl.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB
        //};
        private void RenderPrims(RegionContextBase rcontext, RegionRenderInfo rri)
        {
            GL.Enable(EnableCap.DepthTest);
            GL.Enable(EnableCap.Texture2D);

            lock (rri.renderPrimList) {
            bool firstPass = true;
            // GL.Disable(EnableCap.Blend);
            GL.Enable(EnableCap.Blend);
            GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
            GL.Enable(EnableCap.DepthTest);

            GL.Enable(EnableCap.Normalize);

            GL.EnableClientState(ArrayCap.TextureCoordArray);
            GL.EnableClientState(ArrayCap.VertexArray);
            GL.EnableClientState(ArrayCap.NormalArray);

            StartRender:

            List<RenderablePrim> rpList = new List<RenderablePrim>(rri.renderPrimList.Values);
            // sort back to front
            rpList.Sort(delegate(RenderablePrim rp1, RenderablePrim rp2) {
                return (int)(((OMV.Vector3.Distance(m_renderer.Camera.Position, rp1.Prim.Position)) -
                    (OMV.Vector3.Distance(m_renderer.Camera.Position, rp2.Prim.Position))) * 100f);
            });
            foreach (RenderablePrim rp in rpList) {
                // if this prim is not visible, just loop
                if (!rp.isVisible) continue;

                RenderablePrim prp = RenderablePrim.Empty;
                OMV.Primitive prim = rp.Prim;

                if (prim.ParentID != 0) {
                    // Get the parent reference
                    if (!rri.renderPrimList.TryGetValue(prim.ParentID, out prp)) {
                        // Can't render a child with no parent prim, skip it
                        continue;
                    }
                }

                GL.PushName(prim.LocalID);
                GL.PushMatrix();

                if (prim.ParentID != 0) {
                    // Apply parent translation and rotation
                    GL.MultMatrix(Math3D.CreateTranslationMatrix(prp.Position));
                    GL.MultMatrix(Math3D.CreateRotationMatrix(prp.Rotation));
                }

                // Apply prim translation and rotation
                GL.MultMatrix(Math3D.CreateTranslationMatrix(rp.Position));
                // apply region offset for multiple regions
                GL.MultMatrix(Math3D.CreateTranslationMatrix(CalcRegionOffset(rp.rcontext)));
                GL.MultMatrix(Math3D.CreateRotationMatrix(rp.Rotation));

                // Scale the prim
                GL.Scale(prim.Scale.X, prim.Scale.Y, prim.Scale.Z);

                // Draw the prim faces
                for (int j = 0; j < rp.Mesh.Faces.Count; j++) {
                    OMVR.Face face = rp.Mesh.Faces[j];
                    FaceData data = (FaceData)face.UserData;
                    OMV.Color4 color = face.TextureFace.RGBA;
                    bool alpha = false;
                    int textureID = 0;

                    if (color.A < 1.0f)
                        alpha = true;

                    TextureInfo info;
                    if (face.TextureFace.TextureID != OMV.UUID.Zero
                                && face.TextureFace.TextureID != OMV.Primitive.TextureEntry.WHITE_TEXTURE
                                && m_renderer.Textures.TryGetValue(face.TextureFace.TextureID, out info)) {
                        if (info.Alpha) alpha = true;

                        textureID = info.ID;
                        // if textureID has not been set, need to generate the mipmaps
                        if (textureID == 0) {
                            GenerateMipMaps(rp.acontext, face.TextureFace.TextureID, out textureID);
                            info.ID = textureID;
                        }

                        // Enable texturing for this face
                        GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
                    }
                    else {
                        if (face.TextureFace.TextureID == OMV.Primitive.TextureEntry.WHITE_TEXTURE ||
                                        face.TextureFace.TextureID == OMV.UUID.Zero) {
                            GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill);
                        }
                        else {
                            GL.PolygonMode(MaterialFace.Front, PolygonMode.Line);
                        }
                    }

                    // if (firstPass && !alpha || !firstPass && alpha) {
                        // GL.Color4(color.R, color.G, color.B, color.A);
                        float[] matDiffuse = { color.R, color.G, color.B, color.A };
                        GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, matDiffuse);

                        // Bind the texture
                        if (textureID != 0) {
                            GL.Enable(EnableCap.Texture2D);
                            GL.BindTexture(TextureTarget.Texture2D, textureID);
                        }
                        else {
                            GL.Disable(EnableCap.Texture2D);
                        }

                        GL.TexCoordPointer(2, TexCoordPointerType.Float, 0, data.TexCoords);
                        GL.VertexPointer(3, VertexPointerType.Float, 0, data.Vertices);
                        GL.NormalPointer(NormalPointerType.Float, 0, data.Normals);
                        GL.DrawElements(BeginMode.Triangles, data.Indices.Length, DrawElementsType.UnsignedShort, data.Indices);
                    // }
                }

                GL.PopMatrix();
                GL.PopName();
            }

            /*
            if (firstPass) {
                firstPass = false;
                GL.Enable(EnableCap.Blend);
                GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha);
                // GL.Disable(EnableCap.DepthTest);

                goto StartRender;
            }
             */
            }

            GL.Enable(EnableCap.DepthTest);
            GL.Disable(EnableCap.Texture2D);
        }
Пример #8
0
        private void RenderOcean(RegionContextBase rcontext, RegionRenderInfo rri)
        {
            GL.PushMatrix();

            // apply region offset
            GL.MultMatrix(Math3D.CreateTranslationMatrix(CalcRegionOffset(rcontext)));

            GL.PopMatrix();
            return;
        }
Пример #9
0
        private void RenderAvatars(RegionContextBase rcontext, RegionRenderInfo rri)
        {
            OMV.Vector3 avatarColor = ModuleParams.ParamVector3(m_renderer.m_moduleName + ".OGL.Avatar.Color");
            float avatarTransparancy = ModuleParams.ParamFloat(m_renderer.m_moduleName + ".OGL.Avatar.Transparancy");
            float[] m_avatarMaterialColor = {avatarColor.X, avatarColor.Y, avatarColor.Z, avatarTransparancy};

            lock (rri.renderAvatarList) {
            foreach (RenderableAvatar rav in rri.renderAvatarList.Values) {
                GL.PushMatrix();
                GL.Translate(rav.avatar.RegionPosition.X,
                    rav.avatar.RegionPosition.Y,
                    rav.avatar.RegionPosition.Z);

                GL.Material(MaterialFace.FrontAndBack, MaterialParameter.Diffuse, m_avatarMaterialColor);
                GL.Disable(EnableCap.Texture2D);
                Glu.GLUquadric quad = Glu.gluNewQuadric();
                Glu.gluSphere(quad, 0.5d, 10, 10);
                Glu.gluDeleteQuadric(quad);

                GL.PopMatrix();
            }
            }
        }
Пример #10
0
 private void RenderAnimations(float timeSinceLastFrame, RegionContextBase rcontext, RegionRenderInfo rri)
 {
     AnimatBase.ProcessAnimations(timeSinceLastFrame, rri);
 }
Пример #11
0
 private void ComputeVisibility(RegionContextBase rcontext, RegionRenderInfo rri)
 {
     m_renderer.Camera.ComputeFrustum();
     lock (rri.renderPrimList) {
     foreach (uint ind in rri.renderPrimList.Keys) {
         RenderablePrim rp = rri.renderPrimList[ind];
         rp.isVisible = m_renderer.Camera.isVisible(rp.Position.X, rp.Position.Y, rp.Position.Z, 10f);
     }
     }
     return;
 }
Пример #12
0
 public virtual bool Process(float timeSinceLastFrame, RegionRenderInfo rri)
 {
     return false;   // false saying to delete
 }
Пример #13
0
 // create and initialize the renderinfoblock
 private RegionRenderInfo GetRegionRenderInfo(RegionContextBase rcontext)
 {
     RegionRenderInfo ret = null;
     if (!rcontext.TryGet<RegionRenderInfo>(out ret)) {
     ret = new RegionRenderInfo();
     rcontext.RegisterInterface<RegionRenderInfo>(ret);
     ret.oceanHeight = rcontext.TerrainInfo.WaterHeight;
     }
     return ret;
 }