Beispiel #1
0
        public RealProg(Renderer _renderer)
        {
            renderer = _renderer;
            renderer.cameraPosition.Z = -15;

            Shader myder = renderer.createBasicShader();

            //Uncomment for AABB collisions

            // physicsworld.testtype = CollisionTestType.AABB;
            myder.Draw();

            Bitmap mmap = new Bitmap("pic.jpg");
            Texture2D mtex = renderer.createTextureFromBitmap(mmap);
            mtex.Draw();
            rtex = renderer.createTexture(512, 512);

            rtex.Draw();
            Mesh[] meshes = Primitives.LoadMesh("playercube.obj", flip);

            collisiontester = new PhysicalObject(meshes[0].meshverts, 5, CollisionType.Dynamic, physicsworld);
            collisiontester.Position = new Vector3D(-5, 0, 0);

            mainmesh = meshes[0];
            foreach (Mesh mesh in meshes)
            {
                VertexBuffer tbuff = renderer.CreateVertexBuffer(mesh.meshverts, mesh.meshtexas, mesh.meshnorms);
                rotatingbuffer = tbuff;
                if (mesh.bitmap != null)
                {
                    Console.WriteLine("BITMAP RENDER");
                    Texture2D tt = renderer.createTextureFromBitmap(mesh.bitmap);
                    tt.Draw();
                }
                tbuff.Draw();
            }
            mtex.Draw();
            Mesh cube = Primitives.LoadMesh("playercube.obj", flip)[0];

            theobject = new PhysicalObject(cube.meshverts, 9, CollisionType.Dynamic, physicsworld);

            collisiontester.ownedVBO = rotatingbuffer;
            theobject.ownedVBO = renderer.CreateVertexBuffer(cube.meshverts, cube.meshtexas, cube.meshnorms);

            theobject.ownedVBO.Draw();

            physicsworld.physicalobjects.Add(theobject);
            physicsworld.physicalobjects.Add(collisiontester);

            Mesh anothercube = Primitives.LoadMesh("playercube.obj", flip)[0];
            PhysicalObject mobject = new PhysicalObject(anothercube.meshverts.Clone() as Vector3D[], 1, CollisionType.Dynamic, physicsworld);
            mobject.ownedVBO = renderer.CreateVertexBuffer(anothercube.meshverts, anothercube.meshtexas, anothercube.meshnorms);
            physicsworld.physicalobjects.Add(mobject);
            mobject.ownedVBO.Draw();
            mobject.Position = new Vector3D(30, 0, 0);
            //Set physics properties

            theobject.Weight = 1;

            collisiontester.Weight = 1;

            //collisiontester.Velocity = new Vector3D(.05f, 0, 0);
            theobject.Position = new Vector3D(15, 0, 0);
            theobject.IsCube = true;
            theobject.Weight = 9999999;
            mobject.IsCube = true;

            //End physics properties

            physicsworld.Start();

            physicsworld.physicsUpdateFrame += new System.Threading.ThreadStart(physicsworld_physicsUpdateFrame);

            System.Threading.Thread mthread = new System.Threading.Thread(thetar);
            mthread.Start();
            #if PHONE
            renderer.defaultTouchpad.onTouchMoved += new TouchEvent(defaultTouchpad_onTouchMoved);
            renderer.defaultTouchpad.onTouchFound += new TouchEvent(defaultTouchpad_onTouchFound);
            renderer.defaultTouchpad.onTouchLost += new TouchEvent(defaultTouchpad_onTouchLost);
            #endif
            #if !PHONE
            renderer.defaultKeyboard.onKeyDown += new keyboardeventargs(defaultKeyboard_onKeyDown);
            renderer.defaultKeyboard.onKeyUp += new keyboardeventargs(defaultKeyboard_onKeyUp);
            renderer.defaultMouse.onMouseMove += new mouseEvent(defaultMouse_onMouseMove);
            renderer.defaultMouse.onMouseDown += new mouseEvent(defaultMouse_onMouseDown);
            #endif
        }
Beispiel #2
0
        static void Main(string[] args)
        {
            try
            {
                renderer = new DirectEngine();
            }
            catch (Exception)
            {
                renderer = new GLRenderer();
            }
            Shader mder = renderer.createBasicShader();
            mder.Draw();
            Bitmap mmap = new Bitmap("pic.jpg");

            Texture2D mtex = renderer.createTextureFromBitmap(mmap);
            mtex.Draw();
            Bitmap mbumpmap = new Bitmap("terrain2.bmp");
            TerrainLoader mloader = new TerrainLoader(mbumpmap,7);
            mloader.normals.Clear();
            for (int i = 0; i < mloader.vertices.Count; i++)
            {
                if (i < mloader.vertices.Count - 3)
                {
                    mloader.normals.Add(NormalComputation.ComputeFaceNormal(mloader.vertices[i], mloader.vertices[i + 1], mloader.vertices[i + 2]));
                }
                else
                {
                    mloader.normals.Add(NormalComputation.ComputeFaceNormal(mloader.vertices[i], mloader.vertices[i - 1], mloader.vertices[i - 2]));
                }
            }
            VertexBuffer mbuffer = renderer.CreateVertexBuffer(mloader.vertices.ToArray(),mloader.texcoords.ToArray(),mloader.normals.ToArray());
            renderer.SetPrimitiveMode(PrimitiveMode.TriangleStrip);
            mbuffer.Draw();
            //renderer.cameraPosition.Z = -5;

            renderer.defaultKeyboard.onKeyDown+= HandleRendererdefaultKeyboardonKeyDown;
            renderer.defaultKeyboard.onKeyUp+= HandleRendererdefaultKeyboardonKeyUp;
            float motionspeed = .1f;

            renderer.cameraPosition.Z = -10;
            renderer.cameraPosition.X = 5;
            renderer.cameraPosition.Y = 7;
            while (true)
            {
                //mbuffer.rotation.Y+=.01f;

                if(down) {
                renderer.cameraPosition.Z -=motionspeed;

                }
                if(up) {
                renderer.cameraPosition.Z +=motionspeed;
                }
                if(left) {
                renderer.cameraPosition.X-=motionspeed;
                }
                if(right) {
                renderer.cameraPosition.X+=motionspeed;
                }

                System.Threading.Thread.Sleep(10);
            }
        }
Beispiel #3
0
        public static void Main(string[] args)
        {
            try {

               // throw new Exception();
                renderer = new DirectXLib.DirectEngine();
                flip = true;
            }catch(Exception) {
                renderer = new GLRenderer();
                flip = false;
            }
            renderer.cameraPosition.Z = -5;

            Shader myder = renderer.createBasicShader();

               //Uncomment for AABB collisions

             //physicsworld.testtype = CollisionTestType.AABB;
            myder.Draw();

            Bitmap mmap = new Bitmap("pic.jpg");

            Texture2D mtex = renderer.createTextureFromBitmap(mmap);
            Bitmap newmap = new Bitmap("pic.jpg");
            Graphics tfix = Graphics.FromImage(newmap);
            tfix.DrawString("Hello world!", new Font(FontFamily.GenericMonospace, 16), Brushes.Red, new PointF(0, 0));
            tfix.Dispose();
            mtex.UploadBitmap(newmap);
            mtex.Draw();
            rtex = renderer.createTexture(512, 512);

            rtex.Draw();
            Mesh[] meshes = Primitives.LoadMesh("playercube.obj",flip);

            collisiontester = new PhysicalObject(meshes[0].meshverts, 5, CollisionType.Dynamic,physicsworld);
            collisiontester.Position = new Vector3D(-5, 0, 0);

            mainmesh = meshes[0];
            foreach (Mesh mesh in meshes)
            {
                VertexBuffer tbuff = renderer.CreateVertexBuffer(mesh.meshverts, mesh.meshtexas, mesh.meshnorms);
                rotatingbuffer = tbuff;
                if (mesh.bitmap != null)
                {
                    Console.WriteLine("BITMAP RENDER");
                    Texture2D tt = renderer.createTextureFromBitmap(mesh.bitmap);
                    tt.Draw();
                }
                tbuff.Draw();
            }
            mtex.Draw();
            Mesh cube = Primitives.LoadMesh("playercube.obj",flip)[0];

            theobject = new PhysicalObject(cube.meshverts, 9, CollisionType.Dynamic,physicsworld);

            collisiontester.ownedVBO = rotatingbuffer;
            theobject.ownedVBO = renderer.CreateVertexBuffer(cube.meshverts, cube.meshtexas, cube.meshnorms);

            theobject.ownedVBO.Draw();

            physicsworld.physicalobjects.Add(theobject);
            physicsworld.physicalobjects.Add(collisiontester);

            Mesh anothercube = Primitives.LoadMesh("playercube.obj",flip)[0];
            PhysicalObject mobject = new PhysicalObject(anothercube.meshverts.Clone() as Vector3D[], 1, CollisionType.Dynamic,physicsworld);
            mobject.ownedVBO = renderer.CreateVertexBuffer(anothercube.meshverts, anothercube.meshtexas, anothercube.meshnorms);
            physicsworld.physicalobjects.Add(mobject);
            mobject.ownedVBO.Draw();
            mobject.Position = new Vector3D(30, 0, 0);
            //Set physics properties

            theobject.Weight = 1;

            collisiontester.Weight = 1;

            //collisiontester.Velocity = new Vector3D(.05f, 0, 0);
            theobject.Position = new Vector3D(15, 0, 0);
            theobject.IsCube = true;
            theobject.Weight = 9999999;
            mobject.IsCube = true;

            //End physics properties

            physicsworld.Start();

            physicsworld.physicsUpdateFrame += new System.Threading.ThreadStart(physicsworld_physicsUpdateFrame);

            System.Threading.Thread mthread = new System.Threading.Thread(thetar);
            mthread.Start();
            foreach (Keyboard et in renderer.GetExtensionKeyboards())
            {
                et.onKeyDown += new keyboardeventargs(defaultKeyboard_onKeyDown);
                et.onKeyUp += new keyboardeventargs(defaultKeyboard_onKeyUp);

            }
            renderer.defaultMouse.onMouseMove += new mouseEvent(defaultMouse_onMouseMove);
            renderer.defaultMouse.onMouseDown += new mouseEvent(defaultMouse_onMouseDown);
            //Draw a quad
            List<Vector3D> overts = new List<Vector3D>();
            List<Vector3D> onorms = new List<Vector3D>();
            List<Vector2D> ocords = new List<Vector2D>();
            //Triangle 0

            overts.Add(new Vector3D(-1,-1,0));
            overts.Add(new Vector3D(-1,1,0));
            overts.Add(new Vector3D(1,1,0));
            ocords.Add(new Vector2D(0,0));
            ocords.Add(new Vector2D(0,1));
            ocords.Add(new Vector2D(1,1));
            //Triangle 1
            overts.Add(new Vector3D(1,1,0));
            overts.Add(new Vector3D(1,-1,0));
            overts.Add(new Vector3D(-1,-1,0));
            ocords.Add(new Vector2D(1,1));
            ocords.Add(new Vector2D(1,0));
            ocords.Add(new Vector2D(0,0));
            float zfactor = 900;
            for(int i = 0;i<overts.Count;i++) {
            //Translate by -1

                overts[i] = new Vector3D((overts[i].X)*zfactor,(overts[i].Y)*zfactor,overts[i].Z);
            }
            for(int i = 0;i<overts.Count;i++) {
            onorms.Add(new Vector3D(1,1,1));
            }
            mbuff = renderer.CreateVertexBuffer(overts.ToArray(),ocords.ToArray(),onorms.ToArray());
            mbuff.IsStatic = true;
            mbuff.Position.Z = zfactor;

            //rtex.Draw();
            mbuff.Draw();
            mtex.Draw();
        }
Beispiel #4
0
        public RealProg(Renderer renderer)
        {
            Shader myder = renderer.createBasicShader();
            World physicsworld = new World();
            //Uncomment for AABB collisions

            // physicsworld.testtype = CollisionTestType.AABB;
            myder.Draw();
            Texture2D mtex = renderer.createTexture(512, 512);
            mtex.Draw();

            Mesh[] meshes = Primitives.LoadMesh("test.obj");
            collisiontester = new PhysicalObject(meshes[0].meshverts, 5, CollisionType.Dynamic, physicsworld);

            mainmesh = meshes[0];
            foreach (Mesh mesh in meshes)
            {
                VertexBuffer tbuff = renderer.CreateVertexBuffer(mesh.meshverts, mesh.meshtexas, mesh.meshnorms);
                rotatingbuffer = tbuff;
                if (mesh.bitmap != null)
                {
                    Console.WriteLine("BITMAP RENDER");
                    Texture2D tt = renderer.createTextureFromBitmap(mesh.bitmap);
                    tt.Draw();
                }
                tbuff.Draw();
            }
            Mesh cube = Primitives.LoadMesh("playercube.obj")[0];

            theobject = new PhysicalObject(cube.meshverts, 9, CollisionType.Dynamic, physicsworld);

            collisiontester.ownedVBO = rotatingbuffer;
            theobject.ownedVBO = renderer.CreateVertexBuffer(cube.meshverts, cube.meshtexas, cube.meshnorms);

            theobject.ownedVBO.Draw();

            physicsworld.physicalobjects.Add(theobject);
            physicsworld.physicalobjects.Add(collisiontester);
            //theobject.Velocity = new Vector3D(-.01f, 0, 0);
            Mesh anothercube = Primitives.LoadMesh("playercube.obj")[0];
            PhysicalObject mobject = new PhysicalObject(anothercube.meshverts.Clone() as Vector3D[], 1, CollisionType.Dynamic, physicsworld);
            mobject.ownedVBO = renderer.CreateVertexBuffer(anothercube.meshverts, anothercube.meshtexas, anothercube.meshnorms);
            physicsworld.physicalobjects.Add(mobject);
            mobject.ownedVBO.Draw();
            mobject.Position = new Vector3D(30, 0, 0);
            //Set physics properties
            // collisiontester.Velocity = new Vector3D(.2f, 0, 0);
            theobject.Weight = 1;
            //Uncomment for an inelastic collision
            //collisiontester.mode = CollisionMode.Inelastic;
            collisiontester.Weight = 1;

            collisiontester.Velocity = new Vector3D(.05f, 0, 0);
            theobject.Position = new Vector3D(15, 0, 0);
            //collisiontester.Velocity = new Vector3D(-.2f, 0, 0);
            //End physics properties

            physicsworld.Start();
            List<Vector3D> vectors = new List<Vector3D>();
            List<Vector2D> texcoords = new List<Vector2D>();
            List<Vector3D> normals = new List<Vector3D>();
            for (int i = 0; i < 3; i++)
            {
                normals.Add(new Vector3D(1, 1, 1));
            }
            vectors.Add(new Vector3D(0, 0, 0));
            vectors.Add(new Vector3D(8, 0, 0));
            vectors.Add(new Vector3D(8, 8, 0));
            texcoords.Add(new Vector2D(0, 0));
            texcoords.Add(new Vector2D(1, 0));
            texcoords.Add(new Vector2D(1, 1));
            VertexBuffer tribuffer = renderer.CreateVertexBuffer(vectors.ToArray(), texcoords.ToArray(), normals.ToArray());
            tribuffer.DepthTesting = false;
            tribuffer.IsStatic = true;
            tribuffer.Draw();

            renderer.cameraPosition.Z = -25;
            renderer.cameraPosition.X = -16;
            //Primitives.createRectangle(renderer, 0, 0, 0, 10, 10).Draw();
            System.Threading.Thread mthread = new System.Threading.Thread(thetar);
            mthread.Start();
        }