Пример #1
0
        //private static Vector2[] uv = new Vector2[]{new Vector2(1,0), new Vector2(0,0), new Vector2(0,1), new Vector2(1,1)};
        public List<Vertex> GetVertices(OctreeNode node, Block block, Chunk chunk, World world)
        {
            List<Vertex> vertices = new List<Vertex>();

            int x = (int)(chunk.GetWorldLocation().X + node.origin.X),
                y = (int)(chunk.GetWorldLocation().Y + node.origin.Y),
                z = (int)(chunk.GetWorldLocation().Z + node.origin.Z);

            for(int face = 0; face < 6; face++){
                Vector2[] uv = block.GetUV(face);
                Block block2 = world.GetBlock(x + (addsX[face] * node.blockSize), y + (addsX[face + 6] * node.blockSize), z + (addsX[face + 12] * node.blockSize));
                if(!block2.material.solid)
                {
                    int baseCorner = face * 4;
                    for(int corner = 0; corner < 4; corner++){
                        Vertex vertex = new Vertex(corners[quadsOrder[baseCorner + corner]] * node.blockSize);
                        vertex.position += node.origin - new Vector3(node.blockSize / 2f, node.blockSize / 2f, node.blockSize / 2f);
                        vertex.color = block.material.color * brightness[face];
                        vertex.normal.X = node.blockSize;
                        vertex.normal.Y = block.GetSheetX(face);
                        vertex.normal.Z = block.GetSheetY(face);
                        vertex.texCoord = uv[corner];
                        vertices.Add(vertex);
                        triangles += 2;
                    }
                }
            }
            return vertices;
        }
Пример #2
0
 public void CheckBlock(int x, int y, int z, int addX, int addY, int addZ, Block otherblock, World world)
 {
     Block other = world.GetBlock (x + addX, y + addY, z + addZ);
     if (other == Block.empty) {
         world.SetBlockSilent (x + addX, y + addY, z + addZ, Block.water);
         world.AddToUpdateQueue (x + addX, y + addY, z + addZ, x, y, z, otherblock);
     }
 }
Пример #3
0
        public static CollisionObject CollisionCheckWorld(Entity ent, World world, CollisionObject collisionObject)
        {
            List<CollisionObject> objects = new List<CollisionObject>();
            List<CollisionBox> boxes = new List<CollisionBox>();

            //The size of our search
            Vector3 addvec = (Vector3.One * 2);
            for(int x = (int)-addvec.X; x < (int)addvec.X; x++)
            {
                for(int y = (int)-addvec.Y; y < (int)addvec.Y; y++)
                {
                    for(int z = (int)-addvec.X; z < (int)addvec.Z; z++)
                    {
                        Block block = world.GetBlock(collisionObject.prePosition + new Vector3(x,y,z));
                        if(block.collide)
                            boxes.Add(world.GetCollisionBox(collisionObject.prePosition + new Vector3(x,y,z)));
                    }
                }
            }
            foreach(Entity e in EntityManager.instance.GetEntitiesInRadius(ent, collisionObject.prePosition, 2))
            {
                if(e.HasComponentOfType(typeof(PhysicsComponent)))
                {
                    PhysicsComponent physComponent = (PhysicsComponent)e.GetComponentOfType(typeof(PhysicsComponent));
                    CollisionObject collObj = physComponent.collisionObject;
                    objects.Add( collObj );
                }
            }
            return CollisionManager.Collision(collisionObject, objects.ToArray(), boxes.ToArray());
        }