Exemplo n.º 1
0
        static public void InitializeGeometry()
        {
            //dlaczego musze tutaj dac ball2.obj, a przy ball.obj dostaje gigantyczna kulke? przeciez nawet nie ma ball.obj
            var F = new WavefrontLoader.WaveFrontObjFile("ball2.obj");

            ClothGeometry = F.Geometry;
            Plane         = CGeometry.Plane(device);
            Boxes         = new List <CGeometry>();
            BoxMatrices   = new Dictionary <Actor, Matrix>();

            Balls        = new List <CGeometry>();
            BallMatrices = new Dictionary <Actor, Matrix>();

            Camera = new SDXCamera();
            phi    = 0; theta = 0; radius = Plane.BSphere.Radius * 3;

            Camera.SetPositionSpherical(phi, theta, radius);
            Camera.Target = Plane.BSphere.Center + new Vector3(0.0f, Plane.BSphere.Radius, 0.0f);
            Camera.Up     = new Vector3(0, 1, 0);

            Projection = Matrix.PerspectiveFovLH((float)Math.PI / 4, (float)MainWindow.ClientSize.Width / (float)MainWindow.ClientSize.Height, 0.01f, Plane.BSphere.Radius * 300);

            //moja kamera
            myCamera   = new Camera(new Vector3(25.0f, 25f, 25f), new Vector3(0.0f, 0.0f, 1.0f), MainWindow.ClientSize.Width, MainWindow.ClientSize.Height, (float)Math.PI / 3);
            Projection = myCamera.ProjectionMat;

            LightPosition = new Vector3(Plane.BSphere.Radius * 2, 0.3f, 0.5f);
        }
Exemplo n.º 2
0
        public Ph.Cloth AddCloth(WavefrontLoader.WFOGeometry G, PhMath.Vector3 InitialPosition)
        {
            Ph.ClothMeshDescription clothMeshDesc = new Ph.ClothMeshDescription();
            clothMeshDesc.AllocateVertices <WavefrontLoader.WFOVertex>(G.VertexCount);
            clothMeshDesc.AllocateTriangles <int>(G.IndexCount);

            clothMeshDesc.VertexCount   = G.VertexCount;
            clothMeshDesc.TriangleCount = G.IndexCount / 3;

            clothMeshDesc.VerticesStream.SetData(G.Vertices);
            clothMeshDesc.TriangleStream.SetData(G.Indices);

            clothMeshDesc.Flags &= ~Ph.MeshFlag.Indices16Bit;

            MemoryStream M = new MemoryStream();

            Ph.Cooking.InitializeCooking();
            Ph.Cooking.CookClothMesh(clothMeshDesc, M);
            Ph.Cooking.CloseCooking();
            M.Position = 0;

            Ph.ClothMesh CM = Core.CreateClothMesh(M);

            Ph.ClothDescription ClothDesc = new Ph.ClothDescription();
            ClothDesc.ClothMesh = CM;
            ClothDesc.Pressure  = 4f;
            ClothDesc.SelfCollisionThickness = 3.0f;
            ClothDesc.Friction            = 0.5f;
            ClothDesc.SleepLinearVelocity = 0.1f;
            ClothDesc.Thickness           = 1f;
            ClothDesc.Flags      = Ph.ClothFlag.Gravity | Ph.ClothFlag.Damping | Ph.ClothFlag.CollisionTwoway | Ph.ClothFlag.Pressure | Ph.ClothFlag.Bending;
            ClothDesc.GlobalPose = PhMath.Matrix.Translation(InitialPosition);
            ClothDesc.MeshData.AllocatePositions <WavefrontLoader.WFOVertex>(G.VertexCount);
            ClothDesc.MeshData.AllocateIndices <int>(G.IndexCount);
            ClothDesc.MeshData.AllocateNormals <SlimDX.Vector3>(G.VertexCount);
            ClothDesc.Thickness = 0.1f;
            ClothDesc.Density   = 0.1f;
            ClothDesc.MeshData.MaximumVertices = G.VertexCount;
            ClothDesc.MeshData.MaximumIndices  = G.IndexCount;

            ClothDesc.MeshData.NumberOfVertices = G.VertexCount;
            ClothDesc.MeshData.NumberOfIndices  = G.IndexCount;

            // if (ClothDesc.CheckValid() == 0) return null;
            return(Scene.CreateCloth(ClothDesc));
        }
Exemplo n.º 3
0
        static public void RenderFrame()
        {
            device.ClearDepthStencilView(depthview, DepthStencilClearFlags.Depth, 1, 0);
            device.ClearRenderTargetView(renderview, Color.Blue);
            device.OutputMerger.DepthStencilState = depthstate;
            UpdateLight();
            time += 0.001f;
            // if (count == 500) AddBox();
            // if (count > 1000) { AddBall(); count = 0; }
            // count++;

            EffectTechnique            t    = effect.GetTechniqueByName("SimpleLight");
            RasterizerStateDescription desc = new RasterizerStateDescription();

            desc.CullMode = CullMode.None;
            desc.FillMode = FillMode.Wireframe;  //dlaczego to nei dziala?

            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(DiffuseResource);
            //byle co, i tak renderuje tylko boxy i plane'y
            effect.GetVariableByName("xMaxMass").AsScalar().Set(MaxMass);
            effect.GetVariableByName("xMass").AsScalar().Set(1);


            SetMatrices(Matrix.RotationX(-(float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, -0.2f, 0));
            Plane.Render(t);

            SetMatrices(Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 50f, -100));
            Plane.Render(t);


            SetMatrices(Matrix.RotationY((float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(-100f, 50f, 0));
            Plane.Render(t);

            SetMatrices(Matrix.RotationY(-(float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(100, 50f, 0));
            Plane.Render(t);

            SetMatrices(Matrix.RotationY(-(float)Math.PI) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 50f, 100));
            Plane.Render(t);

            SetMatrices(Matrix.RotationX((float)Math.PI / 2) * Matrix.Scaling(10, 10, 10) * Matrix.Translation(0, 100f, 0));
            Plane.Render(t);


            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse2Resource);


            int i = 0;

            foreach (var M in BoxMatrices)
            {
                SetMatrices(M.Value);
                if (i < howManyBeginningActors)
                {
                    SetMatrices(ScaleMatrixNoTranslation(M.Value, scale));
                    effect.GetVariableByName("xMass").AsScalar().Set(Engine.Actors[i + 7].Mass);
                }

                Boxes[i].Render(t);
                i++;
            }

            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse3Resource);

            i = 0;
            foreach (var M in BallMatrices)
            {
                SetMatrices(M.Value);
                Balls[i].Render(t);
                i++;
            }
            effect.GetVariableByName("xDiffuseTexture").AsResource().SetResource(Diffuse2Resource);
            foreach (var C in Engine.Scene.Cloths)
            {
                WavefrontLoader.WFOGeometry G = new WavefrontLoader.WFOGeometry(device, C, ClothGeometry);

                SetMatrices(Matrix.Identity);
                G.Render(device, t);
            }

            Engine.Step();  //dlaczego zmienia mi tutaj moje BoxMatrices? chyba w sumie musi zeby karta wiedziala co ma wyrenderowac


            swapchain.Present(0, PresentFlags.None);
            prevFrameX = curFrameX;
            prevFrameY = curFrameY;
        }