public void init()
        {
            // Init random generator
            _rand = new Random((int)DateTime.Now.Ticks);

            // Load character with walk animation
            int characterRes     = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "man.scene.xml", 0);
            int characterWalkRes = Horde3D.addResource(Horde3D.ResourceTypes.Animation, "man.anim", 0);

            Horde3DUtils.loadResourcesFromDisk("content");

            // Add characters
            for (int i = 0; i < 100; ++i)
            {
                Particle p = new Particle();

                // Add character to scene and apply animation
                p.node = Horde3D.addNodes(Horde3D.RootNode, characterRes);
                Horde3D.setupModelAnimStage(p.node, 0, characterWalkRes, string.Empty, false);

                // Characters start in a circle formation
                p.px = (float)Math.Sin((i / 100.0f) * 6.28f) * 20.0f;
                p.pz = (float)Math.Cos((i / 100.0f) * 6.28f) * 20.0f;

                chooseDestination(ref p);

                Horde3D.setNodeTransform(p.node, p.px, 0.02f, p.pz, 0, 0, 0, 1, 1, 1);

                _particles.Add(p);
            }
        }
Beispiel #2
0
        public void mainLoop(float fps)
        {
            _curFPS = fps;
            _timer += 1 / fps;

            Horde3D.setOption(Horde3D.EngineOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f);

            if (!_freeze)
            {
                _animTime += 1.0f / _curFPS;

                // Do animation blending
                Horde3D.setModelAnimParams(_knight, 0, _animTime * 24.0f, _weight);
                Horde3D.setModelAnimParams(_knight, 1, _animTime * 24.0f, 1.0f - _weight);

                // Animate particle system
                Horde3D.advanceEmitterTime(_particleSys, 1.0f / _curFPS);
            }

            // Set camera parameters
            Horde3D.setNodeTransform(Horde3D.PrimeTimeCam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1);


            if (_showFPS)
            {
                // Avoid updating FPS text every frame to make it readable
                if (_timer > 0.3f)
                {
                    _fpsText = string.Format("FPS: {0:F2}", fps);
                    _timer   = 0;
                }

                // Show text
                if (_fpsText != null)
                {
                    Horde3DUtils.showText(_fpsText, 0, 0.95f, 0.03f, 0, _fontMatRes);
                }

                string text = string.Format("Weight: {0:F2}", _weight);
                Horde3DUtils.showText(text, 0, 0.91f, 0.03f, 0, _fontMatRes);
            }

            // Show logo
            Horde3D.showOverlay(0.75f, 0, 0, 0, 1, 0, 1, 0,
                                1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1,
                                7, _logoMatRes);


            // Render scene
            Horde3D.render();

            // Write all messages to log file
            Horde3DUtils.dumpMessages();
        }
Beispiel #3
0
        public void mainLoop(float fps)
        {
            _curFPS = fps;
            _timer += 1 / fps;

            Horde3D.setOption(Horde3D.EngineOptions.DebugViewMode, _debugViewMode ? 1.0f : 0.0f);

            if (!_freeze)
            {
                _crowdSim.update(_curFPS);
            }

            // Set camera parameters
            Horde3D.setNodeTransform(Horde3D.PrimeTimeCam, _x, _y, _z, _rx, _ry, 0, 1, 1, 1);


            if (_showFPS)
            {
                // Avoid updating FPS text every frame to make it readable
                if (_timer > 0.3f)
                {
                    _fpsText = string.Format("FPS: {0:F2}", fps);
                    _timer   = 0;
                }

                // Show text
                if (_fpsText != null)
                {
                    Horde3DUtils.showText(_fpsText, 0, 0.95f, 0.03f, 0, _fontMatRes);
                }
            }

            // Show logo
            Horde3D.showOverlay(0.75f, 0, 0, 0, 1, 0, 1, 0,
                                1, 0.2f, 1, 1, 0.75f, 0.2f, 0, 1,
                                7, _logoMatRes);


            // Render scene
            Horde3D.render();

            // Write all messages to log file
            Horde3DUtils.dumpMessages();
        }
Beispiel #4
0
        public bool init()
        {
            // Initialize engine
            if (!Horde3D.init())
            {
                Horde3DUtils.dumpMessages();
                return(false);
            }

            // Set paths for resources
            Horde3D.setResourcePath(Horde3D.ResourceTypes.SceneGraph, "models");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Geometry, "models");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Animation, "models");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Material, "materials");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Code, "shaders");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Shader, "shaders");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Texture2D, "textures");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.TextureCube, "textures");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Effect, "effects");

            // Load pipeline configuration
            if (!Horde3D.loadPipelineConfig("pipeline_Knight.xml"))
            {
                Horde3DUtils.dumpMessages();
                return(false);
            }

            // Set options
            Horde3D.setOption(Horde3D.EngineOptions.LoadTextures, 1);
            Horde3D.setOption(Horde3D.EngineOptions.TexCompression, 0);
            Horde3D.setOption(Horde3D.EngineOptions.FastAnimation, 0);
            Horde3D.setOption(Horde3D.EngineOptions.AnisotropyFactor, 8);
            Horde3D.setOption(Horde3D.EngineOptions.ShadowMapSize, 2048);

            // Add resources
            // Font
            _fontMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "font.material.xml", 0);
            // Logo
            _logoMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "logo.material.xml", 0);
            // Environment
            int envRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "scene.scene.xml", 0);
            // Knight
            int knightRes      = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "knight.scene.xml", 0);
            int knightAnim1Res = Horde3D.addResource(Horde3D.ResourceTypes.Animation, "knight_order.anim", 0);
            int knightAnim2Res = Horde3D.addResource(Horde3D.ResourceTypes.Animation, "knight_attack.anim", 0);
            // Particle system
            int particleSysRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "particleSys1.scene.xml", 0);


            // Load resources
            Horde3DUtils.loadResourcesFromDisk("content");


            // Add scene nodes
            // Add environment
            Horde3D.addNodes(Horde3D.RootNode, envRes);

            // Add knight
            _knight = Horde3D.addNodes(Horde3D.RootNode, knightRes);
            Horde3D.setNodeTransform(_knight, 0, 0, 0, 0, 180, 0, 0.1f, 0.1f, 0.1f);
            Horde3D.setupModelAnimStage(_knight, 0, knightAnim1Res, string.Empty, false);
            Horde3D.setupModelAnimStage(_knight, 1, knightAnim2Res, string.Empty, false);

            // Attach particle system to hand joint
            int hand = Horde3D.getNodeChild(_knight, "Bip01_R_Hand", 0, true);

            _particleSys = Horde3D.addNodes(hand, particleSysRes);
            Horde3D.setNodeTransform(_particleSys, 0, 40, 0, 90, 0, 0, 1, 1, 1);

            // Add light source
            int light = Horde3D.addLightNode(Horde3D.RootNode, "Light1", 0, "LIGHTING", "SHADOWMAP");

            Horde3D.setNodeTransform(light, 0, 1, 15, 30, 0, 0, 1, 1, 1);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Radius, 30);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.FOV, 90);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapCount, 1);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapBias, 0.01f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_R, 1.0f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_G, 0.7f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_B, 0.7f);

            // Customize post processing effects
            int matRes = Horde3D.findResource(Horde3D.ResourceTypes.Material, "postHDR.material.xml");

            // hdrParams: exposure, brightpass threshold, brightpass offset
            Horde3D.setMaterialUniform(matRes, "hdrParams", 2.5f, 0.6f, 0.06f, 0);

            _initialized = true;

            return(true);
        }
Beispiel #5
0
        public bool init()
        {
            // Initialize engine
            if (!Horde3D.init())
            {
                Horde3DUtils.dumpMessages();
                return(false);
            }

            // Set paths for resources
            Horde3D.setResourcePath(Horde3D.ResourceTypes.SceneGraph, "models");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Geometry, "models");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Animation, "models");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Material, "materials");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Code, "shaders");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Shader, "shaders");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Texture2D, "textures");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.TextureCube, "textures");
            Horde3D.setResourcePath(Horde3D.ResourceTypes.Effect, "effects");

            // Load pipeline configuration
            if (!Horde3D.loadPipelineConfig("pipeline_Chicago.xml"))
            {
                Horde3DUtils.dumpMessages();
                return(false);
            }

            // Set options
            Horde3D.setOption(Horde3D.EngineOptions.LoadTextures, 1);
            Horde3D.setOption(Horde3D.EngineOptions.TexCompression, 0);
            Horde3D.setOption(Horde3D.EngineOptions.AnisotropyFactor, 8);
            Horde3D.setOption(Horde3D.EngineOptions.ShadowMapSize, 2048);
            Horde3D.setOption(Horde3D.EngineOptions.FastAnimation, 0);

            // Add resources
            // Font
            _fontMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "font.material.xml", 0);
            // Logo
            _logoMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "logo.material.xml", 0);
            // Shader for deferred shading
            int lightMatRes = Horde3D.addResource(Horde3D.ResourceTypes.Material, "light.material.xml", 0);
            // Environment
            int envRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "scene.scene.xml", 0);

            // Skybox
            //int skyBoxRes = Horde3D.addResource(Horde3D.ResourceTypes.SceneGraph, "skybox.scene.xml", 0);


            // Load resources
            Horde3DUtils.loadResourcesFromDisk("content");


            // Add scene nodes
            // Add environment
            Horde3D.addNodes(Horde3D.RootNode, envRes);
            // Add skybox
            //int sky = Horde3D.addNodes( Horde3D.RootNode, skyBoxRes );
            //Horde3D.setNodeTransform(sky, 0, 0, 0, 0, 0, 0, 210, 50, 210);
            // Add light source
            int light = Horde3D.addLightNode(Horde3D.RootNode, "Light1", lightMatRes, "LIGHTING", "SHADOWMAP");

            Horde3D.setNodeTransform(light, 0, 25, -25, -120, 0, 0, 1, 1, 1);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Radius, 100);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.FOV, 90);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapCount, 3);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowSplitLambda, 0.95f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_R, 0.98f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_G, 0.6f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_B, 0.5f);

            // Add light source
            light = Horde3D.addLightNode(Horde3D.RootNode, "Light2", lightMatRes, "LIGHTING", "SHADOWMAP");
            Horde3D.setNodeTransform(light, 0, 25, 30, -60, 0, 0, 1, 1, 1);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Radius, 50);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.FOV, 90);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowMapCount, 3);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.ShadowSplitLambda, 0.95f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_R, 0.5f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_G, 0.6f);
            Horde3D.setLightParam(light, Horde3D.LightNodeParams.Col_B, 0.98f);

            _crowdSim = new CrowdSim();
            _crowdSim.init();

            _initialized = true;

            return(true);
        }
        public void update(float fps)
        {
            // Parameters for three repulsion zones
            float d1 = 0.25f, d2 = 2.0f, d3 = 4.5f;
            float f1 = 3.0f, f2 = 1.0f, f3 = 0.1f;

            for (int i = 0; i < _particles.Count; ++i)
            {
                Particle p = _particles[i];

                // Reset force
                p.fx = 0; p.fz = 0;

                // Calculate distance to destination
                float dist = (float)Math.Sqrt((p.dx - p.px) * (p.dx - p.px) + (p.dz - p.pz) * (p.dz - p.pz));

                // If destination not reached walk to destination
                if (dist > 3.0f)
                {
                    // Calculate normalized attraction force to destination
                    float afx = (p.dx - p.px) / dist;
                    float afz = (p.dz - p.pz) / dist;

                    p.fx += afx * 0.035f; p.fz += afz * 0.035f;

                    // Repulsion forces from other particles
                    for (int j = 0; j < _particles.Count; ++j)
                    {
                        if (j == i)
                        {
                            continue;
                        }

                        Particle p2 = _particles[j];

                        float dist2    = (float)Math.Sqrt((p.px - p2.px) * (p.px - p2.px) + (p.pz - p2.pz) * (p.pz - p2.pz));
                        float strength = 0;

                        float rfx = (p.px - p2.px) / dist2;
                        float rfz = (p.pz - p2.pz) / dist2;

                        // Use three zones with different repulsion strengths
                        if (dist2 <= d3 && dist2 > d2)
                        {
                            float m = (f3 - 0) / (d2 - d3);
                            float t = 0 - m * d3;
                            strength = m * dist2 + t;
                        }
                        else if (dist2 <= d2 && dist2 > d1)
                        {
                            float m = (f2 - f3) / (d1 - d2);
                            float t = f3 - m * d2;
                            strength = m * dist2 + t;
                        }
                        else if (dist2 <= d1)
                        {
                            float m = (f1 - f2) / (0 - d1);
                            float t = f2 - m * d1;
                            strength = m * dist2 + t;
                        }

                        p.fx += rfx * strength; p.fz += rfz * strength;
                    }
                }
                else
                {
                    // Choose new destination
                    chooseDestination(ref p);
                }

                // Make movement frame rate independence
                p.fx *= (30 / fps);
                p.fz *= (30 / fps);
                float vel = (float)Math.Sqrt(p.fx * p.fx + p.fz * p.fz);

                // Set new position
                p.px += p.fx; p.pz += p.fz;

                // Caluclate orientation
                p.ox = (p.ox + p.fx) / 2;
                p.oz = (p.oz + p.fz) / 2;

                // Get rotation from orientation
                float ry = 0;
                if (p.oz != 0)
                {
                    ry = (float)Math.Atan2(p.ox, p.oz);
                }
                ry *= 180 / 3.1415f;            // Convert from radians to degrees

                // Update character scene node position
                Horde3D.setNodeTransform(p.node, p.px, 0.02f, p.pz, 0, ry, 0, 1, 1, 1);

                // Update animation
                p.animTime += vel * 35.0f;
                Horde3D.setModelAnimParams(p.node, 0, p.animTime, 1.0f);
            }
        }