示例#1
0
        static bool Render()
        {
            float seconds = (float)stopwatch.ElapsedMilliseconds / 1000.0f;
            float aspect  = graphics.Screen.AspectRatio;
            float fov     = FMath.Radians(45.0f);

            Matrix4 proj = Matrix4.Perspective(fov, aspect, 1.0f, 1000000.0f);
            Matrix4 view = Matrix4.LookAt(new Vector3(0.0f, 0.5f, 3.0f),
                                          new Vector3(0.0f, 0.5f, 0.0f),
                                          Vector3.UnitY);
            Matrix4 world = Matrix4.RotationY(1.0f * seconds);

            Matrix4 worldViewProj = proj * view * world;

            program.SetUniformValue(0, ref worldViewProj);


            graphics.SetViewport(0, 0, graphics.Screen.Width, graphics.Screen.Height);
            graphics.SetClearColor(0.0f, 0.5f, 1.0f, 0.0f);
            graphics.Clear();

            graphics.SetShaderProgram(program);
            graphics.SetVertexBuffer(0, vertices);
            graphics.DrawArrays(DrawMode.TriangleStrip, 0, 3);


            SampleDraw.DrawText("Triangle Sample", 0xffffffff, 0, 0);

            graphics.SwapBuffers();
            return(true);
        }
示例#2
0
        static void Init()
        {
            stopwatch = new Stopwatch();
            graphics  = new GraphicsContext();
            SampleDraw.Init(graphics);

            DspWidth  = graphics.Screen.Width;
            DspHeight = graphics.Screen.Height;

            sceneList = new List <IScene>();
            sceneList.Add(new SceneSimpleShader());
            sceneList.Add(new SceneVertexLightingShader());
            sceneList.Add(new SceneGouraudShader());
            sceneList.Add(new ScenePhongShader());
            sceneList.Add(new SceneGlossMapShader());
            sceneList.Add(new SceneTextureShader());
            sceneList.Add(new SceneMultiTextureShader());
            sceneList.Add(new SceneToonShader());
            sceneList.Add(new SceneFogShader());
            sceneList.Add(new SceneBumpMapShader());
            sceneList.Add(new SceneProjectionShadow());

            // graphics context
            graphics.SetViewport(0, 0, DspWidth, DspHeight);
            graphics.SetClearColor(0.0f, 0.5f, 1.0f, 1.0f);
            graphics.Enable(EnableMode.DepthTest);
            graphics.Enable(EnableMode.CullFace);
            graphics.SetCullFace(CullFaceMode.Back, CullFaceDirection.Ccw);

            // camera
            float aspect = DspWidth / (float)DspHeight;
            float fov    = FMath.Radians(45.0f);

            camera = new Camera(fov, aspect, 10.0f, 100.0f);

            // light
            light         = new LightModel();
            light.Color   = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            light.Ambient = new Vector4(0.3f, 0.3f, 0.3f, 1.0f);

            // model
//        model = new Model( BasicMeshFactory.CreateSphere( 4.0f, 20 ) );
            model               = new Model(BasicMeshFactory.CreateTorus(3.0f, 1.0f, 40, 12));
            model.Position      = new Vector3(0.0f, 4.0f, 0.0f);
            model.DiffuseColor  = new Vector4(0.5f, 0.5f, 1.0f, 1.0f);
            model.AmbientColor  = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);
            model.SpecularColor = new Vector4(1.0f, 1.0f, 1.0f, 1.0f);

            // Bg
            modelBg = new BgModel(40.0f, 40.0f, 10, 10);

            id = 0;
            sceneList[id].Setup(graphics, model);

            stopwatch.Start();
        }
示例#3
0
		public Matrix4 getProjectionMatrix() {
			if(!this.pmnr) return this.projectionMatrix;
			this.projectionMatrix = Matrix4.Perspective(
				FMath.Radians(this.fieldOfView),
				getDisplayManager().getGraphicsContext().GetFrameBuffer().AspectRatio,
				this.zNear,
				this.zFar
			);
			return this.projectionMatrix;
		}
        private void get_rotation(ref float x, ref float y, float cx, float cy, float deg)
        {
            float dx  = x - cx;            // 中心からの距離(X)
            float dy  = y - cy;            // 中心からの距離(Y)
            float rad = FMath.Radians(deg);

            float tmpX = (dx * FMath.Cos(rad)) - (dy * FMath.Sin(rad));             // 回転
            float tmpY = (dx * FMath.Sin(rad)) + (dy * FMath.Cos(rad));

            x = (cx + tmpX);             // 元の座標にオフセットする
            y = (cy + tmpY);
        }
示例#5
0
        public void Initialize()
        {
            aspect = gc.Screen.AspectRatio;
            fov    = FMath.Radians(45.0f);
            near   = 1.0f;
            far    = 1000.0f;

            proj = Matrix4.Perspective(fov, aspect, near, far);

            eye    = new Vector3(0.0f, 0.0f, 10.0f);
            center = new Vector3(0.0f, 0.0f, 0.0f);
            up     = Vector3.UnitY;

            /*CalcCameraPosメソッドにおいて注視点が原点じゃない時でも動くかテスト用*/

/*			eye = new Vector3(0.0f, 0.0f, 10.0f);
 *                      center = new Vector3(2.0f, 0.0f, 0.0f);
 *                      cameraUp = new Vector3(0.0f, 1.0f, 0.0f);*/

            world = Matrix4.Identity;
        }
示例#6
0
        static void RenderToOffScreen(float seconds)
        {
            FrameBuffer currentBuffer = graphics.GetFrameBuffer();

            float   aspect        = currentBuffer.AspectRatio;
            float   fovy          = FMath.Radians(45.0f);
            Matrix4 proj          = Matrix4.Perspective(fovy, aspect, 1.0f, 1000000.0f);
            Matrix4 view          = Matrix4.LookAt(new Vector3(0.0f, 0.5f, 3.0f), new Vector3(0.0f, 0.5f, 0.0f), Vector3.UnitY);
            Matrix4 world         = Matrix4.RotationY(1.0f * seconds);
            Matrix4 worldViewProj = proj * view * world;

            vcolorShader.SetUniformValue(0, ref worldViewProj);

            graphics.SetViewport(0, 0, currentBuffer.Width, currentBuffer.Height);
            graphics.SetClearColor(1.0f, 1.0f, 1.0f, 1.0f);
            graphics.Clear();

            graphics.SetShaderProgram(vcolorShader);
            graphics.SetVertexBuffer(0, triangleVertices);

            graphics.Enable(EnableMode.CullFace, false);
            graphics.DrawArrays(DrawMode.Triangles, 0, triangleVertices.VertexCount);
        }
示例#7
0
        internal void DrawSprites(DemoGame.GraphicsDevice graphDev)
        {
            FrameBuffer fbuffer = graphicsContext.GetFrameBuffer();
//		Matrix4 projection = Matrix4.Ortho( 0, fbuffer.Width, fbuffer.Height, 0, -100.0f, 100.0f ) ;
            float   aspect     = graphicsContext.Screen.AspectRatio;
            float   fov        = FMath.Radians(45.0f);
            Matrix4 projection = graphDev.GetCurrentCamera().ViewProjection;

//		graphicsContext.Enable( EnableMode.Blend ) ;
            graphDev.Graphics.Enable(EnableMode.CullFace);
            graphDev.Graphics.SetCullFace(CullFaceMode.None, CullFaceDirection.Ccw);
            graphDev.Graphics.Disable(EnableMode.DepthTest);
            graphicsContext.SetVertexBuffer(0, vertexBuffer);
            for (var sprite = drawList; sprite != null; sprite = sprite.drawNext)
            {
                var material = sprite.Material;
                graphicsContext.SetShaderProgram(material.ShaderProgram);
                material.ShaderProgram.SetUniformValue(0, ref projection);
                graphicsContext.SetBlendFunc(material.BlendFunc);
                graphicsContext.SetTexture(0, material.Texture);
                int next = (sprite.drawNext == null) ? indexCount : sprite.drawNext.indexID;
                graphicsContext.DrawArrays(DrawMode.Triangles, sprite.indexID, next - sprite.indexID);
            }
        }