예제 #1
0
        private void Q3ModelViewerForm_Load(object sender, EventArgs e)
        {
            PresentParameters pp = new PresentParameters();

            pp.Windowed               = true;
            pp.SwapEffect             = SwapEffect.Discard;
            pp.EnableAutoDepthStencil = true;
            pp.AutoDepthStencilFormat = DepthFormat.D24X8;
            pp.BackBufferFormat       = Format.A8R8G8B8;

            d3dDevice = new Device(0, DeviceType.Hardware, this,
                                   CreateFlags.HardwareVertexProcessing | CreateFlags.PureDevice, pp);

            d3dDevice.DeviceReset += new EventHandler(d3dDevice_DeviceReset);

            d3dDevice.RenderState.CullMode            = Cull.None;
            d3dDevice.TextureState [0].ColorOperation = TextureOperation.SelectArg1;
            d3dDevice.SamplerState [0].MinFilter      = TextureFilter.Anisotropic;
            d3dDevice.SamplerState [0].MagFilter      = TextureFilter.Anisotropic;
            d3dDevice.SamplerState [0].MipFilter      = TextureFilter.Anisotropic;

            input = new Input(this,
                              Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive,
                              Microsoft.DirectX.DirectInput.CooperativeLevelFlags.Background | Microsoft.DirectX.DirectInput.CooperativeLevelFlags.NonExclusive);
            camera = new FpsCamera(input,
                                   ( float )d3dDevice.PresentationParameters.BackBufferWidth / d3dDevice.PresentationParameters.BackBufferHeight,
                                   ( float )Math.PI / 4, 1.0f, 5000.0f);
            camera.Position    = new Vector3(0.0f, 20.0f, -20);
            camera.Sensitivity = 5.0f;
            camera.MoveSpeed   = 50.0f;

            textureNotFound = Texture.FromBitmap(d3dDevice, Resources.texture_not_found, Usage.None, Pool.Managed);

            this.LoadModel(@"models/weapons2/rocketl/rocketl.md3");
        }
예제 #2
0
파일: Q3Map.cs 프로젝트: vsugrob/Q3Bot
        public int FindVisibleFaces(FpsCamera camera, int [] facesToRender)
        {
            int leaf;
            int visCluster;

            for (int i = 0; i < visibleFaces.Length; i++)
            {
                visibleFaces [i] = 0;
            }

            leaf = FindLeaf(camera.Position);

            visCluster = leafs [leaf].cluster;

            int faceindex;
            int renderindex = 0;

            for (int i = 0; i < leafs.Length; i++)
            {
                if (isClusterVisible(visCluster, leafs [i].cluster))
                {
                    bool vis = camera.ViewFrustum.isBoxInside(leafs [i].mins, leafs [i].maxs);

                    if (vis)
                    {
                        for (int k = 0; k < leafs [i].n_leaffaces; k++)
                        {
                            faceindex = leafFaces [leafs [i].leafface + k];

                            if (visibleFaces [faceindex] == 0)
                            {
                                visibleFaces [faceindex]      = 1;
                                facesToRender [renderindex++] = faceindex;
                            }
                        }
                    }
                }
            }

            facesToRender [renderindex] = -1;

            return(renderindex);
        }
예제 #3
0
파일: Renderer.cs 프로젝트: vsugrob/Q3Bot
        public Renderer(Q3Map map, Device d3dDevice)
        {
            bufferLocks [0] = ibLock;
            bufferLocks [1] = vbLock;
            bufferLocks [2] = bezierIbLock;
            bufferLocks [3] = bezierVbLock;

            this.d3dDevice = d3dDevice;
            this.Map       = map;

            input = new Input(d3dDevice.PresentationParameters.DeviceWindow,
                              DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive,
                              DI.CooperativeLevelFlags.Background | DI.CooperativeLevelFlags.NonExclusive);
            int w = d3dDevice.PresentationParameters.BackBufferWidth;
            int h = d3dDevice.PresentationParameters.BackBufferHeight;

            fpsCamera = new FpsCamera(input, ( float )w / ( float )h, 105.0f * ( float )System.Math.PI / 360.0f, 1.0f, 10000.0f);

            List <Dictionary <string, object> > respawns;

            if (map.GroupedEntities.TryGetValue("info_player_deathmatch", out respawns))
            {
                Random rnd     = new Random();
                int    respIdx = rnd.Next(respawns.Count);
                Dictionary <string, object> props = respawns [respIdx];
                Vector3 respPos = ( Vector3 )props ["origin"];
                //float angle = ( float ) props ["angle"];
                fpsCamera.Position = respPos;
            }

            // Create Vertex Buffer
            vb = new VertexBuffer(typeof(Q3VertexFormats.PositionNormalTexturedLightened),
                                  map.Vertices.Count,
                                  d3dDevice,
                                  Usage.WriteOnly,
                                  Q3VertexFormats.PositionNormalTexturedLightened.Format,
                                  Pool.Default);
            vb.Created += new EventHandler(vb_Created);
            vb_Created(this, null);

            // Create Index Buffer
            ib = new IndexBuffer(typeof(int),
                                 map.MeshVertices.Count,
                                 d3dDevice,
                                 Usage.WriteOnly,
                                 Pool.Default);
            ib.Created += new EventHandler(ib_Created);
            ib_Created(this, null);

            // Calculate Bezier Index Buffer size and ViertexBuffer Size
            int numIndex  = 0;
            int numVertex = 0;

            ReadOnlyCollection <Q3BspFace> faces = map.Faces;
            Q3BspFace face;

            for (int i = 0; i < faces.Count; i++)
            {
                face = faces [i];

                if (face.type == Q3BspFaceType.Patch)
                {
                    Q3BspPatch patch = face.patch;

                    if (patch != null)
                    {
                        for (int j = 0; j < patch.size; j++)
                        {
                            numIndex  += patch.bezier [j].indices.Length;
                            numVertex += patch.bezier [j].vertices.Length;
                        }
                    }
                }
            }

            if (numIndex != 0 && numVertex != 0)
            {
                // Create bezier buffers
                bezierIb = new IndexBuffer(typeof(int),
                                           numIndex,
                                           d3dDevice,
                                           Usage.WriteOnly,
                                           Pool.Default);
                bezierIb.Created += new EventHandler(bezierIb_Created);
                bezierIb_Created(this, null);

                bezierVb = new VertexBuffer(typeof(Q3VertexFormats.PositionNormalTexturedLightened),
                                            numVertex,
                                            d3dDevice,
                                            Usage.WriteOnly,
                                            Q3VertexFormats.PositionNormalTexturedLightened.Format,
                                            Pool.Default);
                bezierVb.Created += new EventHandler(bezierVb_Created);
                bezierVb_Created(this, null);
            }

            font = new Font(d3dDevice, new SysDraw.Font("Courier New", fontSize, fontStyle));
        }