public override void Init() { // ShadowMappingComponent smc; // RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment)); // smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward; Geometry floor = new Geometry(MeshFactory.CreateCube(new Math.Vector3f(-5f, -0.5f, -5f), new Math.Vector3f(5, 0.5f, 5f))); rootNode.AddChild(floor); PhysicsWorld.AddObject(floor, 0.0f); Node test = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\sphere16.obj"); test.SetLocalTranslation(new Math.Vector3f(0, 25, 0)); rootNode.AddChild(test); PhysicsWorld.AddObject(test, 5.0f); Sound cat = (Sound)AssetManager.Load(AssetManager.GetAppPath() + "\\sounds\\cat.wav"); AudioNode an = new AudioNode(cat); test.AddChild(an); InputManager.AddKeyboardEvent(new Input.KeyboardEvent(Input.InputManager.KeyboardKey.Space, () => { an.Play(); })); }
/// <summary> /// 响应鼠标的操作 /// </summary> public void Fire() { if (Start) { PhysicsWorld.RemoveObject(_elasticatedNet); DrawQueue.Remove(_elasticatedNet); } // 创建弹性网并加入到物理世界和绘制队列 _elasticatedNet = new ElasticatedNet( new Vector2D(40, 120).ToSimUnits(), Width, Height, GridSize, Factor ); DrawQueue.Add(_elasticatedNet); PhysicsWorld.AddObject(_elasticatedNet); // 拉扯弹性网 var net = _elasticatedNet.Net; for (int i = 0; i < Width; i++) { net[i, Height - 1].Velocity = new Vector2D(0, 0.1) * 4 * (i >= Width / 2 ? -1 : 1); net[i, Height - 1].InverseMass = 0; } Start = true; }
public override void Init() { Rendering.Light.PointLight pl = new Rendering.Light.PointLight(); pl.Color = new Color4f(0.2f, 0.0f, 0.0f, 1.0f); pl.Position = new Vector3f(0.0f, 0.0f, 0.0f); Environment.PointLights.Add(pl); Environment.FogColor.Set(0.0f, 0.0f, 0.2f, 0.2f); Environment.FogEnd = 360; Environment.FogStart = 35; Environment.DirectionalLight.Color.Set(0.0f, 0.0f, 0.5f, 1.0f); Environment.AmbientLight.Color.Set(0.2f, 0.1f, 0.1f, 1.0f); GameObject hall; rootNode.AddChild(hall = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\hall\\hall.obj")); hall.SetLocalScale(new Math.Vector3f(0.75f, 0.75f, 0.5f)); PhysicsWorld.AddObject(hall, 0.0f); Rendering.NormalMapRenderer nmr; RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera)); RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr)); RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter()); }
private void Instances_OnGeneralizedEvent(InstanceCollectionEventArgs eventArgs) { switch (eventArgs.Type) { case InstanceCollectionEventType.AddObject: PhysicsWorld.AddObject(eventArgs.Reference); break; } }
public override void Init() { Node floor = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\scene.apx"); rootNode.AddChild(floor); PhysicsWorld.AddObject(floor, 0); Node n = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\sphere16.obj"); n.SetLocalTranslation(new Vector3f(0, 50, 0)); rootNode.AddChild(n); //PhysicsWorld.AddObject(n, 1); PhysicsWorld.AddCharacter((DefaultCamera)cam, InputManager, n, 1); }
public RobDemo(Image image) : base(image) { Settings.ContactIteration = 20; _combinedParticle = new CombinedParticle(_vertexs, 3, 1, true); PhysicsWorld.AddObject(_combinedParticle); // 为顶点绑定形状 foreach (var vertex in _combinedParticle.Vertexs) { vertex.BindShape(new Circle(4.ToSimUnits())); } // 增加边缘 PhysicsWorld.CreatePolygonEdge(_edgePoints.ToArray()); // 增加重力 PhysicsWorld.CreateGravity(9.8); DrawQueue.Add(this); Start = true; }
public override void Init() { ShadowMappingComponent smc; RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment, new int[] { 2048, 1024 })); smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward; // Node floor = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\scene.apx"); // rootNode.AddChild(floor); // PhysicsWorld.AddObject(floor, 0); Geometry cube = new Geometry(MeshFactory.CreateCube(new Vector3f(-15, -0.5f, -15f), new Vector3f(15f, 0.5f, 15f))); rootNode.AddChild(cube); PhysicsWorld.AddObject(cube, 0); Node n = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\monkeyhq.obj"); n.SetLocalTranslation(new Vector3f(0, 50, 0)); rootNode.AddChild(n); //PhysicsWorld.AddObject(n, 5, Scene.Physics.PhysicsWorld.PhysicsShape.Box); PhysicsWorld.AddCharacter((DefaultCamera)cam, InputManager, n, 1); }
public override void Init() { Environment.AmbientLight.Color.Set(0.2f, 0.15f, 0.1f, 1.0f); Environment.DirectionalLight.Direction.Set(1.9f, 0.35f, 1.9f).NormalizeStore(); Environment.DirectionalLight.Color.Set(0.5f, 0.3f, 0.1f, 1.0f); ((PerspectiveCamera)Camera).FieldOfView = 75; ShadowMappingComponent smc; RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment)); smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward; Geometry landscape = ((Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\landscape\\map.obj")).GetChildGeom(0); rootNode.AddChild(landscape); landscape.SetShader(typeof(Terrain.TerrainShader)); Material terrainMaterial = new Material(); Texture grass = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass.jpg"); Texture grass_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass_NRM.jpg"); Texture dirt = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt.jpg"); Texture dirt_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt_NRM.jpg"); terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE0, grass); terrainMaterial.SetValue(TerrainMaterial.TEXTURE_SCALE_0, 16); terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL0, grass_nrm); terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE_SLOPE, dirt); terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL_SLOPE, dirt_nrm); terrainMaterial.SetValue(TerrainMaterial.TEXTURE_SCALE_SLOPE, 16); terrainMaterial.SetValue(Material.MATERIAL_CASTSHADOWS, false); terrainMaterial.SetValue(Material.SHININESS, 0.15f); terrainMaterial.SetValue(Material.ROUGHNESS, 0.8f); landscape.Material = terrainMaterial; landscape.SetLocalScale(new Math.Vector3f(3f, 2f, 3f)); PhysicsWorld.AddObject(landscape, 0.0f); AddComponent(new SkydomeComponent()); // Rendering.NormalMapRenderer nmr; // RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera)); // RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr)); GrassPopulator grassPop; rootNode.AddController(grassPop = new GrassPopulator(PhysicsWorld, cam)); grassPop.GenPatches(12, 3, 128); RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter()); }
public override void Init() { Environment.AmbientLight.Color.Set(0.1f, 0.1f, 0.1f, 1.0f); Environment.FogColor.Set(0.2f, 0.3f, 0.45f, 1.0f); Environment.DirectionalLight.Direction.Set(.5f, 1, .5f).NormalizeStore(); Environment.DirectionalLight.Color.Set(1.0f, 0.85f, 0.55f, 1.0f); ((PerspectiveCamera)Camera).FieldOfView = 60; Camera.Far = 330; ShadowMappingComponent smc; RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment)); smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward; /* thing = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\house.obj"); * * for (int i = 0; i < 1; i++) * { * GameObject thing1 = thing.Clone(); * rootNode.AddChild(thing1); * thing1.SetLocalTranslation(new Vector3f(i * 7, -0.5f, 0)); * }*/ // tree = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\tree\\pine\\LoblollyPine.obj"); // tree.SetLocalScale(new Vector3f(0.35f)); // Test an Apex Engine 3D model, with a material created in the material editor /* * // Test an OBJ model, with normal mapping * GameObject loadedObj = AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\house.obj"); * // ((Node)loadedObj).GetChildGeom(0).Material.SetValue(Material.TEXTURE_HEIGHT, Texture.LoadTexture("C:\\Users\\User\\Pictures\\Brick_14_UV_H_CM_1_DISP.jpg")); * rootNode.AddChild(loadedObj); * PhysicsWorld.AddObject(loadedObj, 0.0f); * * // rootNode.AddChild(new Geometry(Rendering.Util.MeshFactory.CreateCube(new Vector3f(-1,-1,-1), new Vector3f(1,1,1)))); * // loadedObj.SetLocalScale(new Math.Vector3f(2, 0.5f, 2f)); * // Rendering.Animation.AnimationController anim = (Rendering.Animation.AnimationController)loadedApx.GetController(typeof(Rendering.Animation.AnimationController)); * // anim.PlayAnimation(1); * * AddComponent(new ApexEngine.Terrain.SimplexTerrain.SimplexTerrainComponent(PhysicsWorld)); * //AddComponent(new ApexEngine.Terrain.ModelTerrain.ModelTerrainComponent(AssetManager.GetAppPath() + "\\models\\terrain", "terrain", "obj")); * * Geometry quadGeom = new Geometry(Rendering.Util.MeshFactory.CreateCube(new Vector3f(-15f, 0.4f, -15f), new Vector3f(15f, 0.5f, 15f))); * // quadGeom.SetLocalTranslation(new Vector3f(0, -8, 0)); * // rootNode.AddChild(quadGeom); * // PhysicsWorld.AddObject(quadGeom, 0.0f); * * Rendering.Light.PointLight pl = new Rendering.Light.PointLight(); * pl.Color = new Vector4f(0.2f, 0.0f, 0.0f, 1.0f); * pl.Position = new Vector3f(0.0f, 7.0f,15.0f); * // Environment.PointLights.Add(pl); * * Rendering.Light.PointLight pl2 = new Rendering.Light.PointLight(); * pl2.Color = new Vector4f(0.0f, 0.3f, 0.1f, 1.0f); * pl2.Position = new Vector3f(0.0f, 1.0f, 0.0f); * // Environment.PointLights.Add(pl2);*/ /* Node loadedApx = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\test_apx.apx"); * loadedApx.SetLocalTranslation(new Math.Vector3f(0f, 45, 0)); * rootNode.AddChild(loadedApx); * PhysicsWorld.AddObject(loadedApx, 1, Scene.Physics.PhysicsWorld.PhysicsShape.Box); * * Cubemap skybox = Cubemap.LoadCubemap(new string[] { AssetManager.GetAppPath() + "\\textures\\frozendusk\\frozendusk_right.jpg", * AssetManager.GetAppPath() + "\\textures\\frozendusk\\frozendusk_left.jpg", * AssetManager.GetAppPath() + "\\textures\\frozendusk\\frozendusk_top.jpg", * AssetManager.GetAppPath() + "\\textures\\frozendusk\\frozendusk_top.jpg", * AssetManager.GetAppPath() + "\\textures\\frozendusk\\frozendusk_front.jpg", * AssetManager.GetAppPath() + "\\textures\\frozendusk\\frozendusk_back.jpg" }); * * loadedApx.GetChildNode(0).GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.1f, 0.6f, 1.0f, 1.0f)); * loadedApx.GetChildNode(0).GetChildGeom(0).Material.SetValue(Material.TEXTURE_ENV, skybox); * loadedApx.GetChildNode(0).GetChildGeom(0).Material.SetValue(Material.SHININESS, 0.4f); * loadedApx.GetChildNode(0).GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, 0.2f); * loadedApx.GetChildNode(0).GetChildGeom(0).Material.SetValue(Material.METALNESS, 0.7f); * loadedApx.GetChildNode(0).GetChildGeom(0).Material.SetValue(Material.SPECULAR_EXPONENT, 2f); * loadedApx.GetChildNode(0).GetChildGeom(0).UpdateShaderProperties();*/ /* Node terrainModel = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\landscape\\landscape.obj"); * Geometry terrainGeom = terrainModel.GetChildGeom(0); * terrainGeom.SetShader(typeof(Terrain.TerrainShader)); * Material terrainMaterial = new Material(); * * Texture grass = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass.jpg"); * Texture grass_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\grass_NRM.jpg"); * Texture dirt = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt.jpg"); * Texture dirt_nrm = AssetManager.LoadTexture(Assets.AssetManager.GetAppPath() + "\\textures\\dirt_NRM.jpg"); * terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE0, grass); * terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL0, grass_nrm); * terrainMaterial.SetValue(TerrainMaterial.TEXTURE_DIFFUSE_SLOPE, dirt); * terrainMaterial.SetValue(TerrainMaterial.TEXTURE_NORMAL_SLOPE, dirt_nrm); * terrainMaterial.SetValue(Material.MATERIAL_CASTSHADOWS, false); * terrainMaterial.SetValue(Material.SHININESS, 0.15f); * terrainMaterial.SetValue(Material.ROUGHNESS, 0.1f); * * terrainGeom.Material = terrainMaterial; * * terrainModel.SetLocalScale(new Vector3f(1, 0.5f, 1)); * rootNode.AddChild(terrainModel); * * PhysicsWorld.AddObject(terrainModel, 0f); */ terrain = new ApexEngine.Terrain.SimplexTerrain.SimplexTerrainComponent(PhysicsWorld); terrain.BiomesEnabled = true; terrain.ChunkAdded += new Terrain.TerrainComponent.ChunkAddedHandler(OnChunkAdd); terrain.ChunkRemoved += new Terrain.TerrainComponent.ChunkRemovedHandler(OnChunkRemove); AddComponent(terrain); AddComponent(new SkydomeComponent()); // tex = (Texture2D)AssetManager.Load(AssetManager.GetAppPath() + "\\textures\\apex3d.png"); // Sprite sprite = new Sprite(); // rootNode.AddChild(sprite); /* ShadowMappingComponent smc; * RenderManager.AddComponent(smc = new ShadowMappingComponent(cam, Environment)); * smc.RenderMode = ShadowMappingComponent.ShadowRenderMode.Forward; */ // Rendering.NormalMapRenderer nmr; // RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera)); // RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr)); RenderManager.PostProcessor.PostFilters.Add(new FXAAFilter()); Node n = (Node)AssetManager.LoadModel(AssetManager.GetAppPath() + "\\models\\monkeyhq.obj"); n.SetLocalTranslation(new Vector3f(0, 100, 0)); n.GetChildGeom(0).Material.SetValue(Material.COLOR_DIFFUSE, new Color4f(0.0f, 0.0f, 0.0f, 1.0f)); n.GetChildGeom(0).Material.SetValue(Material.SHININESS, 1.0f); n.GetChildGeom(0).Material.SetValue(Material.ROUGHNESS, 0.3f); rootNode.AddChild(n); PhysicsWorld.AddObject(n, 250, Scene.Physics.PhysicsWorld.PhysicsShape.Box); // PhysicsWorld.AddCharacter((DefaultCamera)cam, InputManager, n, 1); /*Rendering.NormalMapRenderer nmr; * RenderManager.AddComponent(nmr = new Rendering.NormalMapRenderer(Environment, Camera)); * RenderManager.PostProcessor.PostFilters.Add(new Rendering.PostProcess.Filters.SSAOFilter(nmr));*/ /* * Geometry waterGeom = new Geometry(MeshFactory.CreateQuad()); * waterGeom.SetLocalScale(new Math.Vector3f(10)); * waterGeom.SetLocalRotation(new Math.Quaternion().SetFromAxis(Vector3f.UNIT_X, 90)); * waterGeom.SetShader(typeof(WaterShader)); * waterGeom.Material.SetValue(Material.TEXTURE_DIFFUSE, Texture.LoadTexture(AssetManager.GetAppPath() + "\\textures\\water.jpg")); * waterGeom.Material.SetValue(Material.TEXTURE_NORMAL, Texture.LoadTexture(AssetManager.GetAppPath() + "\\textures\\water_NRM.jpg")); * rootNode.AddChild(waterGeom);*/ // Console.WriteLine("\n\n" + ShaderUtil.FormatShaderProperties((string)ShaderTextLoader.GetInstance().Load(AssetManager.GetAppPath() + "\\shaders\\default.frag"), new ShaderProperties().SetProperty("NORMALS", true))); /* * ServerGameComponent serv; * this.AddComponent(serv = new ServerGameComponent(new ServerHandler((Message msg) => { }))); * serv.Connect(2222);*/ }