Example #1
0
        public override GameObject CreateEntity(Vector3f translation, Vector3f slope)
        {
            int numThingsInCluster = rand.Next(1, 4);
            Node clusterNode = new Node();
            for (int i = 0; i < numThingsInCluster; i++)
            {
                Vector3f clusterLoc;
                clusterLoc = new Vector3f((float)RandomDouble(-3f, 3f), 0, (float)RandomDouble(-3f, 3f));

                Geometry m = (Geometry)model.Clone();

                Vector3f pieceLoc;

                if (i > 0)
                    pieceLoc = clusterLoc.Add(translation);
                else
                    pieceLoc = translation;

            //    pieceLoc.y = this.GetHeight(pieceLoc.x, pieceLoc.z);

                m.SetLocalTranslation(pieceLoc);

                m.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, (float)RandomDouble(0, 359)));
                m.SetLocalScale(new Vector3f((float)this.RandomDouble(1.0, 1.9)));
                clusterNode.AddChild(m);
            }

            return clusterNode;
        }
 public override GameObject CreateEntity(Vector3f translation, Vector3f slope)
 {
     Geometry m = (Geometry)model.Clone();
     m.SetLocalTranslation(translation);
     m.SetLocalScale(new Vector3f((float)this.RandomDouble(0.35, 0.65)));
     return m;
 }
Example #3
0
 public SSAOFilter(NormalMapRenderer normalMapRenderer)
     : base(new ShaderProperties().SetProperty("NO_GI", true), (string)AssetManager.Load(AppDomain.CurrentDomain.BaseDirectory + "\\shaders\\post\\ssao.frag"))
 {
     this.normalMapRenderer = normalMapRenderer;
     noiseTex = AssetManager.LoadTexture(AppDomain.CurrentDomain.BaseDirectory + "\\textures\\noise_ssao.png");
     Random rand = new Random();
     for (int i = 0; i < kernel.Length; i++)
         kernel[i] = new Vector3f((float)rand.NextDouble()*10f, (float)rand.NextDouble() * 10f, (float)rand.NextDouble() * 10f);
 }
 public TerrainChunkNode(PhysicsWorld physicsWorld, TerrainComponent parentT, int x, int z, Vector3f scale, int chunkSize, TerrainChunkNode[] neighbors)
     : base("TerrainChunkNode")
 {
     this.physicsWorld = physicsWorld;
     this.x = x;
     this.z = z;
     this.neighbors = neighbors;
     this.scale = scale;
     this.chunkSize = chunkSize;
     this.parentT = parentT;
 }
Example #5
0
 public Vertex(Vertex other)
 {
     this.position = other.position;
     this.normal = other.normal;
     this.texCoord0 = other.texCoord0;
     this.texCoord1 = other.texCoord1;
     this.tangent = other.tangent;
     this.bitangent = other.bitangent;
     for (int i = 0; i < 4; i++)
     {
         this.boneIndices[i] = other.boneIndices[i];
         this.boneWeights[i] = other.boneWeights[i];
     }
 }
Example #6
0
 public void Update(Vector3f cam)
 {
     if (this.pageState == PageState.UNLOADING)
     {
         if (this.cacheTime > maxCacheTime)
         {
             this.pageState = PageState.UNLOADED;
             cacheTime = 0f;
         }
         else
         {
             cacheTime += 0.2f;
         }
     }
 }
Example #7
0
 public Vector3f CalculateBindingTranslation()
 {
     Vector3f outv = new Vector3f();
     CalculateBindingTranslation(outv);
     modelPos.Set(outv);
     for (int i = 0; i < children.Count; i++)
     {
         if (children[i] is Bone)
         {
             Bone b = (Bone)children[i];
             b.CalculateBindingTranslation();
         }
     }
     return modelPos;
 }
 public virtual float GetHeight(Vector3f position)
 {
     if (hm != null)
     {
         try
         {
             return hm.heights[hm.HeightIndexAt((int)position.x, (int)position.z)] * hm.scale.y;
         }
         catch (Exception ex)
         {
             Console.WriteLine(ex.Message);
             return float.NaN;
         }
     }
     return float.NaN;
 }
Example #9
0
        public static void CalculateTangents(List<Vertex> vertices, List<int> indices)
        {
            for (int i = 0; i < indices.Count; i += 3)
            {
                try
                {
                    Vertex v0 = vertices[indices[i]];
                    Vertex v1 = vertices[indices[i + 1]];
                    Vertex v2 = vertices[indices[i + 2]];

                    Vector2f uv0 = v0.GetTexCoord0();
                    Vector2f uv1 = v1.GetTexCoord0();
                    Vector2f uv2 = v2.GetTexCoord0();

                    Vector3f edge1 = v1.GetPosition().Subtract(v0.GetPosition());
                    Vector3f edge2 = v2.GetPosition().Subtract(v0.GetPosition());

                    Vector2f edge1uv = uv1.Subtract(uv0);
                    Vector2f edge2uv = uv2.Subtract(uv0);

                    float cp = edge1uv.y * edge2uv.x - edge1uv.x * edge2uv.y;
                    if (cp != 0.0f)
                    {
                        float mul = 1.0f / cp;
                        Vector3f tangent = new Vector3f().Set(edge1.Multiply(-edge2uv.y).AddStore(edge2.Multiply(edge1uv.y)));
                        tangent.MultiplyStore(mul);
                        Vector3f bitangent = new Vector3f().Set(edge1.Multiply(-edge2uv.x).AddStore(edge2.Multiply(edge1uv.x)));
                        bitangent.MultiplyStore(mul);

                        tangent.NormalizeStore();
                        bitangent.NormalizeStore();

                        v0.SetTangent(tangent);
                        v1.SetTangent(tangent);
                        v2.SetTangent(tangent);

                        v0.SetBitangent(bitangent);
                        v1.SetBitangent(bitangent);
                        v2.SetBitangent(bitangent);
                    }
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
            }
        }
Example #10
0
        public override GameObject CreateEntity(Vector3f translation, Vector3f slope)
        {
            Node m = (Node)tree.Clone();
            m.AddController(new BillboardControl(this.cam));
                Vector3f pieceLoc;
                    pieceLoc = translation;

                //    pieceLoc.y = this.GetHeight(pieceLoc.x, pieceLoc.z);

                m.SetLocalTranslation(pieceLoc);

                m.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, (float)RandomDouble(0, 359)));
                m.SetLocalScale(new Vector3f((float)this.RandomDouble(0.8f, 1.2f)));
               // ((Geometry)m).SetShader(typeof(DefaultShader));

            return m;
        }
        public ShadowMapRenderer(Environment environment, int[] size, float[] splits, RenderManager rm, Camera viewcam, float splitDistance)
        {
            this.rm = rm;
            this.environment = environment;
            this.v_cam = viewcam;
            this.splitDist = splitDistance;
            Vector3f ld = environment.DirectionalLight.Direction.Normalize();
            this.lightDirection = new Vector3f(-ld.x, -ld.y, -ld.z);
            this.splits = splits;
            this.shadowMapWidth = size[0];
            this.shadowMapHeight = size[1];

            for (int i = 0; i < 8; i++)
            {
                frustumCornersLS[i] = new Vector3f();
                frustumCornersWS[i] = new Vector3f();
            }
        }
 public override TerrainChunkNode CreateNewChunk(PhysicsWorld physicsWorld, TerrainComponent parentT, int x, int z, Vector3f scale, int chunkSize, TerrainChunkNode[] neighbors)
 {
     string assetLoc = directory + "\\" + defaultName + "_" + x.ToString() + "_" + z.ToString() + defaultExt;
     GameObject loadedObj = null;
     if (System.IO.File.Exists(assetLoc))
     {
         loadedObj = Assets.AssetManager.LoadModel(assetLoc);
     }
     else
     {
         assetLoc = directory + "\\" + defaultName + "_0_0" + defaultExt;
         if (System.IO.File.Exists(assetLoc))
         {
             loadedObj = Assets.AssetManager.LoadModel(assetLoc);
         }
     }
     return new ModelTerrainChunkNode(loadedObj, physicsWorld, (ModelTerrainComponent)parentT, x, z, scale, chunkSize, (ModelTerrainChunkNode[])neighbors);
 }
Example #13
0
        public static Mesh CreateCube(Vector3f min, Vector3f max)
        {
            List<Vertex> vertices = new List<Vertex>();
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, max.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, max.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(max.x, min.y, min.z)));
            vertices.Add(new Vertex(new Vector3f(min.x, max.y, min.z)));

            Mesh mesh = new Mesh();
            mesh.SetVertices(vertices);
            return mesh;
        }
Example #14
0
        public Node CreateEntityNode(Vector3f translation, GameObject parentNode, float chunkSize, int entityPerChunk)
        {
            Node n = new Node();
            float mult = chunkSize / (float)entityPerChunk;
            parentNode.UpdateTransform();

            for (int x = 0; x < entityPerChunk; x++)
            {
                for (int z = 0; z < entityPerChunk; z++)
                {
                    float xLoc = (float)RandomDouble(0, chunkSize);
                    float yLoc = 3;
                    float zLoc = (float)RandomDouble(0, chunkSize);

                    yLoc = GetHeight(parentNode.GetWorldTranslation().x + translation.x + xLoc, parentNode.GetWorldTranslation().z + translation.z + zLoc);
                    //	Vec3f norm = getNormal(parentNode, translation.x + x * 4, translation.z + z * 4);
                    if (yLoc != float.NaN)
                    {
                        GameObject entity = CreateEntity(new Vector3f(xLoc, yLoc, zLoc), Vector3f.Zero);
                       // entity.SetLocalScale(new Vector3f((float)RandomDouble(0.1f, 0.5f)));
                        entity.SetLocalRotation(new Quaternion().SetFromAxis(Vector3f.UnitY, (float)RandomDouble(0, 359)));
                        //  n.AddChild(CreateEntity(new Vector3f(x * mult, y, z * mult), Vector3f.ZERO));
                        n.AddChild(entity);
                    }
                }
            }
            if (batchGeometry)
            {
                Node merged = new Node();
                merged.AddChild(new Geometry(MeshUtil.MergeMeshes(n)));
                merged.SetLocalTranslation(translation);
                merged.GetChildGeom(0).SetShader(GetShaderType());
                for (int i = 0; i < n.Children.Count; i++)
                {
                    n.Children[i] = null;
                }
                n = null;
                return merged;
            }
            n.SetLocalTranslation(translation);
            return n;
        }
        public SimplexTerrainMesh(SimplexTerrainComponent parent, int xstart, int zstart, Vector3f scale, int chunkSize, bool generateBiomes)
            : base()
        {
            try
            {
                this.generateBiomes = generateBiomes;
                this.parent = parent;
                this.x = xstart;
                this.z = zstart;
                this.chunkSize = chunkSize;
                this.scale = scale;
                this.GetHeights(this.x, this.z);

                this.RebuildTerrainMesh();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex);
            }
        }
Example #16
0
        public BoundingBox Set(Vector3f minimum, Vector3f maximum)
        {
            min.Set(minimum);
            max.Set(maximum);
            center.Set(min).AddStore(max).MultiplyStore(0.5f);
            dimension.Set(max).SubtractStore(min).MultiplyStore(0.5f);
            UpdateCorners();

            return this;
        }
 public DirectionalLight(Vector3f dir, Vector4f clr)
 {
     direction.Set(dir);
     color.Set(color);
 }
 public DirectionalLight(Vector3f dir)
 {
     direction.Set(dir);
     color.Set(1f, 0.9f, 0.8f, 1.0f);
 }
Example #19
0
 public void SetUniform(string name, Vector3f[] vec)
 {
     for (int i = 0; i < vec.Length; i++)
         SetUniform(name + "[" + i.ToString() + "]", vec[i].X, vec[i].Y, vec[i].Z);
 }
Example #20
0
 public void SetUniform(string name, Vector3f vec)
 {
     SetUniform(name, vec.X, vec.Y, vec.Z);
 }
Example #21
0
 public BoundingBox Extend(Vector3f point)
 {
     return Set(MathUtil.Min(min, point), MathUtil.Max(max, point));
 }
 public override TerrainChunkNode CreateNewChunk(PhysicsWorld physicsWorld, TerrainComponent parentT, int x, int z, Vector3f scale, int chunkSize, TerrainChunkNode[] neighbors)
 {
     return new SimplexTerrainChunkNode(physicsWorld, (SimplexTerrainComponent)parentT, x, z, scale, chunkSize, (SimplexTerrainChunkNode[])neighbors, biomesEnabled);
 }
Example #23
0
 /** Create a single entity. */
 public abstract GameObject CreateEntity(Vector3f translation, Vector3f slope);
Example #24
0
 public override void SetAudioValues(Sound sound, float pitch, float gain, Vector3f position, Vector3f velocity)
 {
     if (openALSupported)
     {
         AL.Source(sound.Source, ALSourcef.Gain, gain);
         AL.Source(sound.Source, ALSourcef.Pitch, pitch);
         AL.Source(sound.Source, ALSource3f.Position, position.x, position.y, position.z);
         AL.Source(sound.Source, ALSource3f.Velocity, velocity.x, velocity.y, velocity.z);
     }
 }
 public ModelTerrainChunkNode(GameObject objToAdd, PhysicsWorld physicsWorld, ModelTerrainComponent parentT, int x, int z, Vector3f scale, int chunkSize, ModelTerrainChunkNode[] neighbors)
     : base(physicsWorld, parentT, x, z, scale, chunkSize, neighbors)
 {
     this.objToAdd = objToAdd;
 }
Example #26
0
 public BoundingBox()
 {
     for (int i = 0; i < corners.Length; i++)
         corners[i] = new Vector3f();
 }
 public void SetTranslation(Vector3f pos)
 {
     if (body != null)
     {
         tmpJVec.Set(pos.x, pos.y, pos.z);
         body.Position = tmpJVec;
         // origin.SubtractStore(boundingBox.Center);
         origin.Set(GameObject.GetUpdatedWorldTranslation());
     }
 }
Example #28
0
 public BoundingBox(Vector3f dimMin, Vector3f dimMax)
 {
     for (int i = 0; i < corners.Length; i++)
         corners[i] = new Vector3f();
     CreateBoundingBox(dimMin, dimMax);
 }
        public Biome GetBiome(Vector3f worldPosition)
        {
            Vector3f chunkSpace1 = WorldToChunkSpace(worldPosition);
            HeightInfo closest = HmWithCoords((int)chunkSpace1.x, (int)chunkSpace1.z);

            if (closest != null)
            {
                chunkSpace1.x -= closest.position.x;
                chunkSpace1.z -= closest.position.y;
                chunkSpace1.MultiplyStore((chunkSize - 1));

                return ((SimplexTerrainChunkNode)closest.chunk).GetBiome(chunkSpace1);
            }
            return null;
        }
Example #30
0
 public BoundingBox CreateBoundingBox(Vector3f minimum, Vector3f maximum)
 {
     return Set(minimum, maximum);
 }