/// <summary> /// Disposes /// </summary> public override void Dispose() { mLightNode = null; mLight = null; mpObjsNode = null; mStaticGeom = null; mAnimState = null; mSceneManager.ClearScene(); mLightWibbler.Dispose(); mLightWibbler = null; //ControllerManager contMgr = ControllerManager.GetSingleton(); //contMgr.DestroyController( mLightCtlFlt ); mLightCtlFlt = null; mWFCF = null; mCFFPtr = null; mCVFPtr = null; mLog.Dispose(); mLog = null; //GC.Collect(); base.Dispose(); }
private void loadZonesLayer(LayerInfo layer) { List <StaticGeometry> waterBodies = new List <StaticGeometry>(); //Set water zones for (int i = 0; i < layer.Objects.Length; i++) { ObjectInfo zoneObject = layer.Objects[i]; if (zoneObject.Type.Equals("Water", StringComparison.OrdinalIgnoreCase)) { if (zoneObject.Polygon == null) { continue; } Vertices simGeo = new Vertices(zoneObject.Polygon.Length); StaticGeometry waterBody = new StaticGeometry(zoneObject.Polygon.Length * 2); //Loop through the object's vertices (Vector2) for (int k = 0; k < zoneObject.Polygon.Length; k++) { simGeo.Add(ConvertUnits.ToSimUnits(zoneObject.Polygon[k])); waterBody.VertexData[k * 2 + 0] = zoneObject.Polygon[k].X + zoneObject.X; waterBody.VertexData[k * 2 + 1] = zoneObject.Polygon[k].Y + zoneObject.Y; } Body geoBody = BodyFactory.CreatePolygon(world, simGeo, 1f); geoBody.Position = ConvertUnits.ToSimUnits(new Vector2(zoneObject.X, zoneObject.Y)); geoBody.UserData = "Water"; geoBody.CollisionCategories = Category.Cat3; geoBody.IsSensor = true; geoBody.OnCollision += (a, b, contact) => { b.Body.GravityScale = 0.05f; return(true); }; geoBody.OnSeparation += (a, b) => { b.Body.GravityScale = 1f; }; waterBody.PhysicsBody = geoBody; waterBodies.Add(waterBody); } else if (zoneObject.Type.Equals("PlayerStart", StringComparison.OrdinalIgnoreCase)) { Vector2 playerStart = new Vector2(); playerStart.X = (zoneObject.X + zoneObject.X + zoneObject.Width) / 2f; playerStart.Y = zoneObject.Y + zoneObject.Height; //Player height is adjusted from the bottom map.PlayerStart = playerStart; } } map.WaterBodies = waterBodies; }
public void AddStaticGeometryToList(StaticGeometry d) { if (StaticObjects == null) { StaticObjects = new List <StaticGeometry>(); } StaticObjects.Add(d); ptsObjectsLoaded += 1; }
public bool Load(string filename) { // shadows Engine.Graphics.SceneManager.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE; Engine.Graphics.SceneManager.AmbientLight = this.ambientLight; Engine.Graphics.SceneManager.ShadowColour = this.ambientLight; if (!LoadWorldEntities()) { return(false); } // static mesh // TODO: implement depth shadow mapping // http://www.ogre3d.org/tikiwiki/Depth+Shadow+Mapping&bl=y&fullscreen=y staticGeometryCaster = Engine.Graphics.SceneManager.CreateStaticGeometry("StaticGeometryCaster"); staticGeometryReceiver = Engine.Graphics.SceneManager.CreateStaticGeometry("StaticGeometryReceiver"); staticGeometryCaster.CastShadows = true; StreamReader reader = new StreamReader(filename); string line = reader.ReadLine(); // skip header if (line != null) { line = reader.ReadLine(); } while (line != null) { string[] bits = line.Split('|'); string key = bits[0]; Vector3 position = StringConverter.ParseVector3(bits[1]); Quaternion orientation = StringConverter.ParseQuaternion(bits[2]); worldEntityMap[key].Spawn(position, orientation); line = reader.ReadLine(); } reader.Close(); staticGeometryCaster.Build(); staticGeometryReceiver.Build(); Engine.Graphics.Camera.Position = new Vector3(0, 0, 0); Engine.Graphics.Camera.Yaw(new Radian(new Degree(-15))); Engine.Sound.SetListenerPosition(Engine.Graphics.Camera.Position, Engine.Graphics.Camera.Direction); return(true); }
/// <summary> /// This method creates 4000 quads and attaches them to the scenegraph as static geometry /// </summary> public void StaticGeometry() { Quad(); staticGeo = mSceneMgr.CreateStaticGeometry("staticQuads"); // Initializes the static geometry container for (int i = 0; i < 200; i++) { for (int j = 0; j < 200; j++) { manualObjEntity = mSceneMgr.CreateEntity("Quad"); // Loads the quad in an entity staticGeo.AddEntity(manualObjEntity, new Vector3(i * 5, j * 5, 0)); // adds it to the scenegraph as static geo } } staticGeo.Build(); // Prepares the static geometry to be rendered }
public void StaticGeometry() { Quad(); staticGeometry = mSceneMgr.CreateStaticGeometry("staticQuads"); for (int i = 0; i < 200; i++) { for (int j = 0; j < 200; j++) { cubeEntity = mSceneMgr.CreateEntity("Quad"); staticGeometry.AddEntity(cubeEntity, new Vector3(i * 5, j * 5, 0)); } } staticGeometry.Build(); }
public StaticGeometryHelper(WorldManager worldMgr, StaticGeometryKind kind, int rebuildTimeThreshold, int nodesAddedThreshold, int nodesRemovedThreshold, int nodesAddedInLastSecondThreshold) { this.worldMgr = worldMgr; this.kind = kind; this.name = (kind == StaticGeometryKind.BigOrLittleNode ? "StaticGeom" : (kind == StaticGeometryKind.BigNode ? "BigNodes" : "LittleNodes")); this.objectGeometry = null; this.rebuildTimeThreshold = rebuildTimeThreshold; this.nodesAddedThreshold = nodesAddedThreshold; this.nodesRemovedThreshold = nodesRemovedThreshold; this.nodesAddedInLastSecondThreshold = nodesAddedInLastSecondThreshold; this.nodesAddedSinceLastRebuild = 0; this.nodesRemovedSinceLastRebuild = 0; this.lastNodesAdded = 0; this.timeOfLastRebuild = 0; this.lastRebuildCheckTime = 0; this.enabled = false; this.force = false; }
public Player(Map map, Vector2 positionBottom) : base(map) { const float height = 8f / 2f; const float width = 5f / 2f; Vertices vertices = new Vertices(3); vertices.Add(ConvertUnits.ToSimUnits(new Vector2(0f, -height))); vertices.Add(ConvertUnits.ToSimUnits(new Vector2(-width, height))); vertices.Add(ConvertUnits.ToSimUnits(new Vector2(width, height))); Body physicsBody = BodyFactory.CreatePolygon(map.World, vertices, 5f); physicsBody.BodyType = BodyType.Dynamic; physicsBody.Position = ConvertUnits.ToSimUnits(positionBottom - new Vector2(0f, height * 2f)); physicsBody.AngularDamping = 300f; physicsBody.LinearDamping = 8f; physicsBody.OnCollision += Rocket_OnCollision; physicsBody.CollisionCategories = Category.Cat1; shape = new StaticGeometry(6); shape.PhysicsBody = physicsBody; shape.VertexData[0] = 0f; shape.VertexData[1] = -height; shape.VertexData[2] = -width; shape.VertexData[3] = height; shape.VertexData[4] = width; shape.VertexData[5] = height; SetPhysicsBody(physicsBody); controller = new PlayerController(this); maxHealth = 100f; currentHealth = maxHealth; }
private void loadCollisionLayer(LayerInfo layer) { List <StaticGeometry> staticLevelGeometry = new List <StaticGeometry>(); //Load static geometry for (int i = 0; i < layer.Objects.Length; i++) { ObjectInfo collisionObject = layer.Objects[i]; if (collisionObject.Polygon == null) { continue; } Vertices simGeo = new Vertices(collisionObject.Polygon.Length); StaticGeometry disGeo = new StaticGeometry(collisionObject.Polygon.Length * 2); //Loop through the object's vertices (Vector2) for (int k = 0; k < collisionObject.Polygon.Length; k++) { simGeo.Add(ConvertUnits.ToSimUnits(collisionObject.Polygon[k])); disGeo.VertexData[k * 2 + 0] = collisionObject.Polygon[k].X + collisionObject.X; disGeo.VertexData[k * 2 + 1] = collisionObject.Polygon[k].Y + collisionObject.Y; } Body geoBody = BodyFactory.CreatePolygon(world, simGeo, 1f); geoBody.Position = ConvertUnits.ToSimUnits(new Vector2(collisionObject.X, collisionObject.Y)); geoBody.UserData = "Static Geometry"; geoBody.CollisionCategories = Category.Cat2; disGeo.PhysicsBody = geoBody; staticLevelGeometry.Add(disGeo); } map.StaticGeometry = staticLevelGeometry; }
// Lock the node dictionary, and rebuild the static // geometry for objects of this kind protected void Rebuild(SceneManager mgr, Dictionary <long, WorldEntity> nodeDictionary) { log.DebugFormat("Entering StaticGeometryHelper.Rebuild for geometry '{0}'", name); long tickStart = TimeTool.CurrentTime; try { nodesAddedSinceLastRebuild = 0; nodesRemovedSinceLastRebuild = 0; force = false; Monitor.Enter(mgr); if (objectGeometry != null) { objectGeometry.Reset(); } else { objectGeometry = new StaticGeometry(mgr, name); } // Dictionary mapping Material into a list of // ObjectNodes in which some submesh uses the material Dictionary <Material, MaterialAndNodeCounts> materialsUsedMap = new Dictionary <Material, MaterialAndNodeCounts>(); lock (nodeDictionary) { foreach (WorldEntity entity in nodeDictionary.Values) { if (entity is ObjectNode) { ObjectNode node = (ObjectNode)entity; // For now, we only consider "props" that have an associated SceneNode // and are direct descendants of the root scene node, and are of the right // kind, i.e., don't have a perception radius if this static geometry is for // little nodes, and vice versa. // log.DebugFormat("StaticGeometry.Rebuild: Examining node {0}, oid {1}, type {2}, sceneNode {3}, InStaticGeometry {4}, top-level {5}", // node.Name, node.Oid, node.ObjectType, node.SceneNode, node.InStaticGeometry, node.SceneNode.Parent == mgr.RootSceneNode); if (node.ObjectType == ObjectNodeType.Prop && (node.InStaticGeometry || (node.SceneNode != null && node.SceneNode.Parent == mgr.RootSceneNode)) && RightKind(node)) { foreach (Material m in node.Entity.SubEntityMaterials) { MaterialAndNodeCounts nodesUsingMaterial; if (!materialsUsedMap.TryGetValue(m, out nodesUsingMaterial)) { nodesUsingMaterial = new MaterialAndNodeCounts(); materialsUsedMap[m] = nodesUsingMaterial; } nodesUsingMaterial.materialUseCount++; int subMeshUseCount; Dictionary <ObjectNode, int> submeshUseCounts = nodesUsingMaterial.submeshUseCounts; if (!submeshUseCounts.TryGetValue(node, out subMeshUseCount)) { submeshUseCounts[node] = 1; } else { submeshUseCounts[node] = subMeshUseCount + 1; } } } } } } // Now we have a count of uses of each material, and // for each node, the number of subentities that use the // material. Now we need to calculate the number of // instance of sharings for each object node Dictionary <ObjectNode, bool> candidateNodes = new Dictionary <ObjectNode, bool>(); foreach (MaterialAndNodeCounts counts in materialsUsedMap.Values) { if (counts.materialUseCount > 1) { foreach (KeyValuePair <ObjectNode, int> pair in counts.submeshUseCounts) { candidateNodes[pair.Key] = true; } } } Dictionary <ObjectNode, int> staticNodes = new Dictionary <ObjectNode, int>(); foreach (KeyValuePair <ObjectNode, bool> pair in candidateNodes) { ObjectNode candidate = pair.Key; bool useIt = pair.Value; if (useIt) { staticNodes[candidate] = 0; } } if (staticNodes.Count == 0) { log.InfoFormat("StaticGeometryHelper.Rebuild: Didn't build static geometry {0} because object count was zero", name); } else { log.InfoFormat("StaticGeometryHelper.Rebuild: {0} ObjectNodes", staticNodes.Count); foreach (ObjectNode staticNode in staticNodes.Keys) { SceneNode sc = staticNode.SceneNode; if (!staticNode.InStaticGeometry) { sc.RemoveFromParent(); staticNode.InStaticGeometry = true; } log.DebugFormat("StaticGeometryHelper.Rebuild: Add node {0} with name {1} to static geometry", staticNode.Oid, staticNode.Name); objectGeometry.AddSceneNode(sc); } } if (lastStaticNodes != null) { foreach (ObjectNode node in lastStaticNodes.Keys) { if (!staticNodes.ContainsKey(node)) { // Only 1 instance of the mesh, so make sure that if in a former build it was in // static geometry, that we add it back to the scene graph. if (node.InStaticGeometry) { SceneNode sn = node.SceneNode; if (sn != null) { mgr.RootSceneNode.AddChild(sn); } node.InStaticGeometry = false; } } } } if (staticNodes.Count > 0) { objectGeometry.Build(); } lastStaticNodes = staticNodes; timeOfLastRebuild = TimeTool.CurrentTime; } finally { Monitor.Exit(mgr); } log.InfoFormat("StaticGeometryHelper.Rebuild: Rebuild of geometry '{0}' took {1} ms", name, TimeTool.CurrentTime - tickStart); }
/// <summary> /// initialize the scene /// </summary> private void InitializeScene() { //create scene mgr sceneMgr = root.CreateSceneManager(SceneType.ST_GENERIC); // Every viewport has a camera associated with it. // The second number is a z-order. Higher z-order viewports // are rendered on top (in the case of multiple viewports). Camera cam = sceneMgr.CreateCamera("cam"); root.AutoCreatedWindow.AddViewport(cam, 0); Viewport vp = root.AutoCreatedWindow.GetViewport(0); vp.BackgroundColour = ColourValue.Black; // have the frustum set the aspect ratio automatically cam.AutoAspectRatio = true; Vector3 position = new Vector3(0.0f, 0.0f, 0.0f); Quaternion orientation = Quaternion.IDENTITY; // In Ogre, an entity is a renderable object. An entity must be attached // to a scene node, however, in order to be rendered. Every entity (really, // every object in Ogre) must be assigned a unique name. shipCam = new ArcballCamera(cam); shipCam.Radius = 250.0f; shipCam.Target = sceneMgr.RootSceneNode; Light l = sceneMgr.CreateLight("point1"); l.DiffuseColour = new ColourValue(1.0f, 1.0f, 1.0f); l.Position = Vector3.UNIT_Y * 100.0f; l.CastShadows = true; l.Type = Light.LightTypes.LT_POINT; sceneMgr.SetSkyBox(true, "Space", 5000); grid = sceneMgr.CreateStaticGeometry("grid"); float radius = 100.0f; Entity cube; const int NUM_CUBES_HALF_WIDTH = 2; for (int i = -NUM_CUBES_HALF_WIDTH; i < NUM_CUBES_HALF_WIDTH; ++i) for (int j = -NUM_CUBES_HALF_WIDTH; j < NUM_CUBES_HALF_WIDTH; ++j) for (int k = -NUM_CUBES_HALF_WIDTH; k < NUM_CUBES_HALF_WIDTH; ++k) { if (i != 0) { cube = sceneMgr.CreateEntity("cube-" + i + "-" + j + "-" + k, SceneManager.PrefabType.PT_CUBE); grid.AddEntity(cube, new Vector3(i, j, k) * radius * 10); } } grid.Build(); shipMgr = new ShipManager(this); }
/// <summary> /// This method creates 4000 quads and attaches them to the scenegraph as static geometry /// </summary> public void StaticGeometry() { Quad(); staticGeo = mSceneMgr.CreateStaticGeometry("staticQuads"); // Initializes the static geometry container for(int i=0; i<200; i++) for (int j = 0; j < 200; j++) { manualObjEntity = mSceneMgr.CreateEntity("Quad"); // Loads the quad in an entity staticGeo.AddEntity(manualObjEntity, new Vector3(i * 5, j * 5, 0)); // adds it to the scenegraph as static geo } staticGeo.Build(); // Prepares the static geometry to be rendered }
protected override void CreateScene() { mLog = LogManager.Singleton.createLog("DemoGrass.log", false, true); mLog.LogMessage(string.Format("DemoGrass log {0}", System.DateTime.Now)); //Init waveGrass varibles xinc = OgreMath.PI * 0.4f; zinc = OgreMath.PI * 0.55f; xpos = OgreMath.RangeRandom(-OgreDotNet.OgreMath.PI, OgreDotNet.OgreMath.PI); zpos = OgreMath.RangeRandom(-OgreDotNet.OgreMath.PI, OgreDotNet.OgreMath.PI); xxoffset = new Math3D.Vector4(0.0f, 0.0f, 0.0f, 0.0f); mSceneManager.SetSkyBox(true, "Examples/SpaceSkyBox"); setupLighting(); mSceneManager.AmbientLightColor = Color.FromArgb(125, 125, 125, 125); //create a ground plain mLog.LogMessage("Point 1"); Plane plane = new Plane(); plane.Normal.x = 0; plane.Normal.y = 1; plane.Normal.z = 0; plane.D = 0; MeshManager.GetSingleton().CreatePlane("Myplane", "General", plane, 14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UnitZ); Entity pPlaneEnt = mSceneManager.CreateEntity("plane", "Myplane"); pPlaneEnt.SetMaterialName("Examples/GrassFloor"); pPlaneEnt.SetCastShadows(false); mSceneManager.GetRootSceneNode().CreateChildSceneNode().AttachObject(pPlaneEnt); //create the grass mesh mLog.LogMessage("Point 2"); createGrassMesh2(); Entity e = null; e = mSceneManager.CreateEntity("1", GRASS_MESH_NAME); //close the the grass mesh in a region StaticGeometry s = mSceneManager.CreateStaticGeometry("bing"); s.setRegionDimensions(new Vector3(1000, 1000, 1000)); // Set the region origin so the centre is at 0 world s.setOrigin(new Vector3(-500, 500, -500)); mLog.LogMessage("Point 3"); for (int x = -1950; x < 1950; x += 150) //1950 { for (int z = -1950; z < 1950; z += 150) { Vector3 pos; pos.x = x + OgreMath.RangeRandom(-25, 25); pos.y = 0; pos.z = z + OgreMath.RangeRandom(-25, 25); Quaternion orientation = Quaternion.FromAngleAxis( new Degree(OgreMath.RangeRandom(0, 359)).ValueDegrees(), Vector3.UnitY); Vector3 scale = new Vector3(1, OgreMath.RangeRandom(0.85f, 1.15f), 1); s.addEntity(e, pos, orientation, scale); } } mLog.LogMessage("Point 4"); s.build(); mStaticGeom = s; //mStaticGeom.dump("Grass.SG.Dump.txt"); //Put an Ogre head in the middle mLog.LogMessage("Point 5"); OgreDotNet.MeshPtr m = MeshManager.GetSingleton().Load("ogrehead.mesh", "General"); Mesh mm = m.Get(); UInt16 src = 0, dest = 0; if (!mm.SuggestTangentVectorBuildParams(ref src, ref dest)) { mLog.LogMessage("got from SuggestTangentVectorBuildParams src=" + src + " dest=" + dest); mm.BuildTangentVectors(src, dest); } e = mSceneManager.CreateEntity("head", "ogrehead.mesh"); e.SetMaterialName("Examples/OffsetMapping/Specular"); SceneNode headNode = mSceneManager.GetRootSceneNode().CreateChildSceneNode(); headNode.AttachObject(e); headNode.SetScale(7, 7, 7); headNode.SetPosition(0, 200, 0); e.SetNormaliseNormals(true); mLog.LogMessage("Point 6"); //setup camera position mCamera.Move(new Vector3(0, 350, 800)); mCamera.LookAt = new Vector3(0, 200, 0); mLog.LogMessage("Point end"); }
/// <summary> /// initialize the scene /// </summary> private void InitializeScene() { //create scene mgr sceneMgr = root.CreateSceneManager(SceneType.ST_GENERIC); // Every viewport has a camera associated with it. // The second number is a z-order. Higher z-order viewports // are rendered on top (in the case of multiple viewports). Camera cam = sceneMgr.CreateCamera("cam"); root.AutoCreatedWindow.AddViewport(cam, 0); Viewport vp = root.AutoCreatedWindow.GetViewport(0); vp.BackgroundColour = ColourValue.Black; // have the frustum set the aspect ratio automatically cam.AutoAspectRatio = true; Vector3 position = new Vector3(0.0f, 0.0f, 0.0f); Quaternion orientation = Quaternion.IDENTITY; // In Ogre, an entity is a renderable object. An entity must be attached // to a scene node, however, in order to be rendered. Every entity (really, // every object in Ogre) must be assigned a unique name. shipCam = new ArcballCamera(cam); shipCam.Radius = 250.0f; shipCam.Target = sceneMgr.RootSceneNode; Light l = sceneMgr.CreateLight("point1"); l.DiffuseColour = new ColourValue(1.0f, 1.0f, 1.0f); l.Position = Vector3.UNIT_Y * 100.0f; l.CastShadows = true; l.Type = Light.LightTypes.LT_POINT; sceneMgr.SetSkyBox(true, "Space", 5000); grid = sceneMgr.CreateStaticGeometry("grid"); float radius = 100.0f; Entity cube; const int NUM_CUBES_HALF_WIDTH = 2; for (int i = -NUM_CUBES_HALF_WIDTH; i < NUM_CUBES_HALF_WIDTH; ++i) { for (int j = -NUM_CUBES_HALF_WIDTH; j < NUM_CUBES_HALF_WIDTH; ++j) { for (int k = -NUM_CUBES_HALF_WIDTH; k < NUM_CUBES_HALF_WIDTH; ++k) { if (i != 0) { cube = sceneMgr.CreateEntity("cube-" + i + "-" + j + "-" + k, SceneManager.PrefabType.PT_CUBE); grid.AddEntity(cube, new Vector3(i, j, k) * radius * 10); } } } } grid.Build(); shipMgr = new ShipManager(this); }
public void CreateScene() { scene.SetSkyBox(true, "Examples/SpaceSkyBox"); SetupLighting(); Plane plane = new Plane(); plane.normal = Vector3.UNIT_Y; plane.d = 0; MeshManager.Singleton.CreatePlane("MyPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UNIT_Z); Entity planeEnt = scene.CreateEntity("plane", "MyPlane"); planeEnt.SetMaterialName("Examples/GrassFloor"); planeEnt.CastShadows = false; scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEnt); Vector3 minV = new Vector3(-2000, 0, -2000); Vector3 maxV = new Vector3(2000, 0, 2000); CreateGrassMesh(); Entity e = scene.CreateEntity("1", GRASS_MESH_NAME); StaticGeometry s = scene.CreateStaticGeometry("bing");//, 1); s.RegionDimensions = new Vector3(1000, 1000, 1000); s.Origin = new Vector3(-500, 500, -500); //Set the region origin so the centre is at 0 world for (int x = -1950; x < 1950; x += 150) { for (int z = -1950; z < 1950; z += 150) { Vector3 pos = new Vector3(x + Math.RangeRandom(-25, 25), 0, z + Math.RangeRandom(-25, 25)); Quaternion orientation =new Quaternion(); orientation.FromAngleAxis(Math.RangeRandom(0, 359), Vector3.UNIT_Y); Vector3 scale = new Vector3(1, Math.RangeRandom(0.85f, 1.15f), 1); s.AddEntity(e, pos, orientation, scale); } } s.Build(); StaticGeom = s; //Mesh mesh = MeshManager.Singleton.Load("ogrehead.mesh", ResourceGroupManager.DefaultResourceGroupName); //short src, dest; //if (!mesh.SuggestTangentVectorBuildParams( VertexElementSemantic.VES_POSITION, out src, out dest)) { // mesh.BuildTangentVectors( VertexElementSemantic.VES_POSITION,src, dest); //} //e = scene.CreateEntity("head", "ogrehead.mesh"); //e.SetMaterialName("Examples/OffsetMapping/Specular"); //HeadNode = scene.RootSceneNode.CreateChildSceneNode(); //HeadNode.AttachObject(e); //HeadNode.Scale = new Vector3(7, 7, 7); //HeadNode.Position = new Vector3(0, 200, 0); //if (e.GetSubEntity(0).NormalizeNormals == false) { // LogManager.Singleton.LogMessage("aie aie aie"); //} Root.Singleton.RenderSystem.SetNormaliseNormals(true); //camera.Move(new Vector3(0, 350, 0)); }
public bool Load(string filename) { // shadows Engine.Graphics.SceneManager.ShadowTechnique = ShadowTechnique.SHADOWTYPE_TEXTURE_MODULATIVE; Engine.Graphics.SceneManager.AmbientLight = this.ambientLight; Engine.Graphics.SceneManager.ShadowColour = this.ambientLight; if (!LoadWorldEntities()) return false; // static mesh // TODO: implement depth shadow mapping // http://www.ogre3d.org/tikiwiki/Depth+Shadow+Mapping&bl=y&fullscreen=y staticGeometryCaster = Engine.Graphics.SceneManager.CreateStaticGeometry("StaticGeometryCaster"); staticGeometryReceiver = Engine.Graphics.SceneManager.CreateStaticGeometry("StaticGeometryReceiver"); staticGeometryCaster.CastShadows = true; StreamReader reader = new StreamReader(filename); string line = reader.ReadLine(); // skip header if (line != null) line = reader.ReadLine(); while (line != null) { string[] bits = line.Split('|'); string key = bits[0]; Vector3 position = StringConverter.ParseVector3(bits[1]); Quaternion orientation = StringConverter.ParseQuaternion(bits[2]); worldEntityMap[key].Spawn(position, orientation); line = reader.ReadLine(); } reader.Close(); staticGeometryCaster.Build(); staticGeometryReceiver.Build(); Engine.Graphics.Camera.Position = new Vector3(0, 0, 0); Engine.Graphics.Camera.Yaw(new Radian(new Degree(-15))); Engine.Sound.SetListenerPosition(Engine.Graphics.Camera.Position, Engine.Graphics.Camera.Direction); return true; }
public void CreateScene() { scene.SetSkyBox(true, "Examples/SpaceSkyBox"); SetupLighting(); Plane plane = new Plane(); plane.normal = Vector3.UNIT_Y; plane.d = 0; MeshManager.Singleton.CreatePlane("MyPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, 14500, 14500, 10, 10, true, 1, 50, 50, Vector3.UNIT_Z); Entity planeEnt = scene.CreateEntity("plane", "MyPlane"); planeEnt.SetMaterialName("Examples/GrassFloor"); planeEnt.CastShadows = false; scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEnt); Vector3 minV = new Vector3(-2000, 0, -2000); Vector3 maxV = new Vector3(2000, 0, 2000); CreateGrassMesh(); Entity e = scene.CreateEntity("1", GRASS_MESH_NAME); StaticGeometry s = scene.CreateStaticGeometry("bing");//, 1); s.RegionDimensions = new Vector3(1000, 1000, 1000); s.Origin = new Vector3(-500, 500, -500); //Set the region origin so the centre is at 0 world for (int x = -1950; x < 1950; x += 150) { for (int z = -1950; z < 1950; z += 150) { Vector3 pos = new Vector3(x + Math.RangeRandom(-25, 25), 0, z + Math.RangeRandom(-25, 25)); Quaternion orientation = new Quaternion(); orientation.FromAngleAxis(Math.RangeRandom(0, 359), Vector3.UNIT_Y); Vector3 scale = new Vector3(1, Math.RangeRandom(0.85f, 1.15f), 1); s.AddEntity(e, pos, orientation, scale); } } s.Build(); StaticGeom = s; //Mesh mesh = MeshManager.Singleton.Load("ogrehead.mesh", ResourceGroupManager.DefaultResourceGroupName); //short src, dest; //if (!mesh.SuggestTangentVectorBuildParams( VertexElementSemantic.VES_POSITION, out src, out dest)) { // mesh.BuildTangentVectors( VertexElementSemantic.VES_POSITION,src, dest); //} //e = scene.CreateEntity("head", "ogrehead.mesh"); //e.SetMaterialName("Examples/OffsetMapping/Specular"); //HeadNode = scene.RootSceneNode.CreateChildSceneNode(); //HeadNode.AttachObject(e); //HeadNode.Scale = new Vector3(7, 7, 7); //HeadNode.Position = new Vector3(0, 200, 0); //if (e.GetSubEntity(0).NormalizeNormals == false) { // LogManager.Singleton.LogMessage("aie aie aie"); //} Root.Singleton.RenderSystem.SetNormaliseNormals(true); //camera.Move(new Vector3(0, 350, 0)); }