예제 #1
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            // Initialize our custom Component Collection
            Components = new GameComponentCollection();

            // Initialize RasterizerState to Enable wireFrames
            wireFrame = new RasterizerState()
            {
                FillMode = FillMode.WireFrame,
                CullMode = CullMode.None,
            };

            // BackBuffer size and stuff
            GraphicsDevice.PresentationParameters.BackBufferHeight = 480;
            GraphicsDevice.PresentationParameters.BackBufferWidth = 640;
            //GraphicsDevice.RasterizerState = wireFrame; // Optional, here for debugging purposes and stuff

            // Create our BasicEffect.
            effect = new BasicEffect(GraphicsDevice);
            //effect.VertexColorEnabled = true;
            effect.EnableDefaultLighting();

            // Content stuff
            content = new ContentManager(Services, "Content");
            // Set our root directory
            content.RootDirectory = "Content";
            // use new spriteBatch
            spriteBatch = new SpriteBatch(GraphicsDevice);
            font = content.Load<SpriteFont>(@"fonts\hudFont");
            backgroundTexture = content.Load<Texture2D>(@"Texturas\bg");
            mainFrame = new Rectangle(0, 0, GraphicsDevice.Viewport.Width, GraphicsDevice.Viewport.Height);

            // Load the primitives we want to be drawn
            // Load the primitives
            primitives.Add(new SpherePrimitive(GraphicsDevice));
            primitives.Add(new CubePrimitive(GraphicsDevice));
            primitives.Add(new CylinderPrimitive(GraphicsDevice));
            primitives.Add(new TorusPrimitive(GraphicsDevice));
            primitives.Add(new EllipticalCylinder(GraphicsDevice));
            primitives.Add(new HyperbollicCylinder(GraphicsDevice));

            // Initialize the renderer for our bounding spheres
            BoundingSphereRenderer.Initialize(GraphicsDevice, 45);

            // Add a new camera to our scene
            camera = new FreeCamera( GraphicsDevice );
            // Attach it as a game component
            Components.Add(camera);

            // Add a new cursor to our scene
            cursor = new Cursor(GraphicsDevice, content, spriteBatch);
            Components.Add(cursor);

            // Set up the mouse and stuff
            Mouse.WindowHandle = this.Handle;

            // Go through every component and execute their Initialize method
            foreach (WinFormComponent component in Components)
            {
                component.Initialize();
            }

            // Start the animation timer.
            stopWatch = Stopwatch.StartNew();

            // Start the size modifier
            size = 1.0f;
            size2 = 1.0f;

            // Get us some stereoscopy going pl0x
            PresentationParameters pp = GraphicsDevice.PresentationParameters;
            renderTarget = new RenderTarget2D(GraphicsDevice, pp.BackBufferWidth, pp.BackBufferHeight, false, GraphicsDevice.DisplayMode.Format, pp.DepthStencilFormat );

            // J00 LET'S PUT OUR NEW WINFORM HERE CUZ WAI NOT
            stereoCopy = new Form2();
            stereoCopy.Show();

            // Hook the idle event to constantly redraw our animation.
            Application.Idle += TickWhileIdle;
        }
예제 #2
0
        /// <summary> 
        /// This Draw overload takes a camera object, which is then used to project the primitive
        /// on the 3D space and then applies any other transformations to the primitive
        /// </summary>
        public void Draw(FreeCamera camera, Color color)
        {
            // Set BasicEffect parameters.
            basicEffect.World = world * transform;
            basicEffect.View = camera.viewMatrix;
            basicEffect.Projection = camera.projectionMatrix;
            basicEffect.DiffuseColor = color.ToVector3();
            basicEffect.Alpha = color.A / 255.0f;

            GraphicsDevice device = basicEffect.GraphicsDevice;
            device.DepthStencilState = DepthStencilState.Default;

            if (color.A < 255)
            {
                // Set renderstates for alpha blended rendering.
                device.BlendState = BlendState.AlphaBlend;
            }
            else
            {
                // Set renderstates for opaque rendering.
                device.BlendState = BlendState.Opaque;
            }

            // Draw the model, using BasicEffect.
            Draw(basicEffect);
        }