/// <summary> /// This method generates a plane in an Entity which will be used as a ground /// </summary> private void GroundPlane() { plane = new Plane(Vector3.UNIT_Y, 0); MeshPtr groundMeshPtr = MeshManager.Singleton.CreatePlane("ground", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, plane, groundWidth, groundHeight, groundXSegs, groundZSegs, true, 1, uTiles, vTiles, Vector3.UNIT_Z); groundEntity = mSceneMgr.CreateEntity("ground"); groundNode = mSceneMgr.CreateSceneNode(); groundNode.AttachObject(groundEntity); mSceneMgr.RootSceneNode.AddChild(groundNode); groundEntity.SetMaterialName("Meteor"); }
/// <summary> /// This method initializes the heart node and entity /// </summary> /// <param name="n"> A numeric tag used to determine the heart postion on sceen </param> /// <returns></returns> private SceneNode CreateHeart(int n) { lifeEntity = mSceneMgr.CreateEntity("Heart.mesh"); lifeEntity.SetMaterialName("HeartHMD"); SceneNode livesNode; livesNode = new SceneNode(mSceneMgr); livesNode.AttachObject(lifeEntity); livesNode.Scale(new Vector3(0.15f, 0.15f, 0.15f)); //livesNode.Position = new Vector3(3f, 3f, -8) - n * 0.5f * Vector3.UNIT_X; ; livesNode.Position = new Vector3(3f, 3.5f, -5.5f) - n * 0.5f * Vector3.UNIT_X; ; livesNode.SetVisible(true); return livesNode; }
protected void BeginNextTask() { //If we're transitioning from a previous task, lets tear that shit down if (currentRenderTask != null) TearDownPreviousTask(); if (currentRenderTask == null && renderTasks.Count == 0) { mShutDown = true; return; } //Dequeue the next task currentRenderTask = renderTasks.Dequeue(); _playerEntity = mSceneMgr.CreateEntity(currentRenderTask.PlayerModelConfig.EntityName, currentRenderTask.PlayerModelConfig.ModelName); _playerNode = mSceneMgr.RootSceneNode.CreateChildSceneNode("PlayerNode"); _playerNode.AttachObject(_playerEntity); _playerNode._setDerivedPosition(_playerNode.Position + new Vector3(0, -0.5f * _playerEntity.BoundingRadius, 0)); //Set up name of dat animation collection var animationCollectionName = currentRenderTask.PlayerModelConfig.EntityName; switch (currentRenderTask.TaskType) { case TaskType.Item: animationCollectionName += "_" + currentRenderTask.ItemConfig.EntityName; break; case TaskType.Wearable: animationCollectionName += "_" + currentRenderTask.WearableConfig.EntityName; break; } mAnimationCollection = new AnimationCollection { Name = animationCollectionName }; mStateIterator = _playerEntity.AllAnimationStates.GetAnimationStateIterator(); if (_playerEntity != null) { switch (currentRenderTask.TaskType) { case TaskType.Item: { _currentItem = mSceneMgr.CreateEntity(currentRenderTask.ItemConfig.EntityName, currentRenderTask.ItemConfig.ModelName); var ic = currentRenderTask.ItemConfig; _playerEntity.AttachObjectToBone(currentRenderTask.PlayerModelConfig.RHandBoneName, _currentItem, new Quaternion(ic.QuatW, ic.QuatX, ic.QuatY, ic.QuatZ), new Vector3(ic.OffsetX, ic.OffsetY, ic.OffsetZ)); //Make player entity transparent so all we see is the item _playerEntity.SetMaterialName("transparent_mask"); } break; case TaskType.Wearable: _playerEntity.SetMaterialName(currentRenderTask.WearableConfig.Material); break; } } //_ent.SetMaterialName("Normal"); /* var sub = _ent.GetSubEntity(0); sub.SetCustomParameter(CUSTOM_SHININESS, new Vector4(10.0f, 0.0f, 0.0f, 0.0f)); sub.SetCustomParameter(CUSTOM_DIFFUSE, new Vector4(1.0f, 1.0f, 0.7f, 1.0f)); sub.SetCustomParameter(CUSTOM_SPECULAR, new Vector4(1.0f, 1.0f, 1.0f, 1.0f));*/ NextAnimation(); }
public override void CreateScene() { //init spline array for (int i = 0; i < NUM_FISH; i++) { fishSplines[i] = new SimpleSpline(); } // Check prerequisites first RenderSystemCapabilities caps = Root.Singleton.RenderSystem.Capabilities; if (!caps.HasCapability(Capabilities.RSC_VERTEX_PROGRAM) || !(caps.HasCapability(Capabilities.RSC_FRAGMENT_PROGRAM))) { throw new System.Exception("Your card does not support vertex and fragment programs, so cannot run this demo. Sorry!"); } else { if (!GpuProgramManager.Singleton.IsSyntaxSupported("arbfp1") && !GpuProgramManager.Singleton.IsSyntaxSupported("ps_2_0") && !GpuProgramManager.Singleton.IsSyntaxSupported("ps_1_4") ) { throw new System.Exception("Your card does not support advanced fragment programs, so cannot run this demo. Sorry!"); } } camera.SetPosition(-50, 125, 760); camera.SetDirection(0, 0, -1); // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.5f, 0.5f, 0.5f); // Create a point light Light l = sceneMgr.CreateLight("MainLight"); l.Type = Light.LightTypes.LT_DIRECTIONAL; l.Direction = -Vector3.UNIT_Y; Entity pEnt; TexturePtr mTexture = TextureManager.Singleton.CreateManual("Refraction", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 512, 512, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET); //RenderTexture* rttTex = mRoot.getRenderSystem().createRenderTexture( "Refraction", 512, 512 ); RenderTarget rttTex = mTexture.GetBuffer().GetRenderTarget(); { Viewport v = rttTex.AddViewport(camera); MaterialPtr mat = MaterialManager.Singleton.GetByName("Examples/FresnelReflectionRefraction"); mat.GetTechnique(0).GetPass(0).GetTextureUnitState(2).SetTextureName("Refraction"); v.OverlaysEnabled = false; rttTex.PreRenderTargetUpdate += new RenderTargetListener.PreRenderTargetUpdateHandler(Refraction_PreRenderTargetUpdate); rttTex.PostRenderTargetUpdate += new RenderTargetListener.PostRenderTargetUpdateHandler(Refraction_PostRenderTargetUpdate); } mTexture = TextureManager.Singleton.CreateManual("Reflection", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 512, 512, 0, PixelFormat.PF_R8G8B8, (int)TextureUsage.TU_RENDERTARGET); //rttTex = mRoot.getRenderSystem().createRenderTexture( "Reflection", 512, 512 ); rttTex = mTexture.GetBuffer().GetRenderTarget(); { Viewport v = rttTex.AddViewport(camera); MaterialPtr mat = MaterialManager.Singleton.GetByName("Examples/FresnelReflectionRefraction"); mat.GetTechnique(0).GetPass(0).GetTextureUnitState(1).SetTextureName("Reflection"); v.OverlaysEnabled = false; rttTex.PreRenderTargetUpdate += new RenderTargetListener.PreRenderTargetUpdateHandler(Reflection_PreRenderTargetUpdate); rttTex.PostRenderTargetUpdate += new RenderTargetListener.PostRenderTargetUpdateHandler(Reflection_PostRenderTargetUpdate); } // Define a floor plane mesh reflectionPlane.normal = Vector3.UNIT_Y; reflectionPlane.d = 0; MeshManager.Singleton.CreatePlane("ReflectPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, reflectionPlane, 1500, 1500, 10, 10, true, 1, 5, 5, Vector3.UNIT_Z); pPlaneEnt = sceneMgr.CreateEntity("plane", "ReflectPlane"); pPlaneEnt.SetMaterialName("Examples/FresnelReflectionRefraction"); sceneMgr.RootSceneNode.CreateChildSceneNode().AttachObject(pPlaneEnt); sceneMgr.SetSkyBox(true, "Examples/CloudyNoonSkyBox"); // My node to which all objects will be attached SceneNode myRootNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); // above water entities pEnt = sceneMgr.CreateEntity( "RomanBathUpper", "RomanBathUpper.mesh" ); myRootNode.AttachObject(pEnt); aboveWaterEnts.Add(pEnt); pEnt = sceneMgr.CreateEntity( "Columns", "Columns.mesh" ); myRootNode.AttachObject(pEnt); aboveWaterEnts.Add(pEnt); SceneNode headNode = myRootNode.CreateChildSceneNode (); pEnt = sceneMgr.CreateEntity( "OgreHead", "ogrehead.mesh" ); pEnt.SetMaterialName ("RomanBath/OgreStone"); headNode.AttachObject(pEnt); headNode.SetPosition(-350,55,130); headNode.Rotate(Vector3.UNIT_Y, new Degree (90)); aboveWaterEnts.Add(pEnt); // below water entities pEnt = sceneMgr.CreateEntity( "RomanBathLower", "RomanBathLower.mesh" ); myRootNode.AttachObject(pEnt); belowWaterEnts.Add(pEnt); for (int fishNo = 0; fishNo < NUM_FISH; ++fishNo) { pEnt = sceneMgr.CreateEntity("fish" + fishNo, "fish.mesh"); fishNodes[fishNo] = myRootNode.CreateChildSceneNode(); fishAnimations[fishNo] = pEnt.GetAnimationState("swim"); fishAnimations[fishNo].Enabled = true; fishNodes[fishNo].AttachObject(pEnt); belowWaterEnts.Add(pEnt); // Generate a random selection of points for the fish to swim to fishSplines[fishNo].SetAutoCalculate(false); Vector3 lastPos = new Vector3(); for (int waypoint = 0; waypoint < NUM_FISH_WAYPOINTS; ++waypoint) { Vector3 pos = new Vector3( Mogre.Math.SymmetricRandom() * 270, -10, Mogre.Math.SymmetricRandom() * 700); if (waypoint > 0) { // check this waypoint isn't too far, we don't want turbo-fish ;) // since the waypoints are achieved every 5 seconds, half the length // of the pond is ok while ((lastPos - pos).Length > 750) { pos = new Vector3( Mogre.Math.SymmetricRandom() * 270, -10, Mogre.Math.SymmetricRandom() * 700); } } fishSplines[fishNo].AddPoint(pos); lastPos = pos; } // close the spline fishSplines[fishNo].AddPoint(fishSplines[fishNo].GetPoint(0)); // recalc fishSplines[fishNo].RecalcTangents(); } }
/// <summary> /// create a bunch of crap /// </summary> void CreateThings() { Light light = mogreImageSource.SceneManager.CreateLight("sun2"); light.Type = Light.LightTypes.LT_DIRECTIONAL; light.Direction = new Vector3(-0.1f, -1, 0.1f); light.Direction.Normalise(); light.DiffuseColour = new ColourValue(1f, 1f, 1f); light.SpecularColour = new ColourValue(1f, 1f, 1f); light.Position = new Vector3(0, 10, 0); light.CastShadows = true; ponyNode = sceneMgr.RootSceneNode.CreateChildSceneNode(); ponyEnt = sceneMgr.CreateEntity("BgPonyColtBody.mesh"); ponyNode.AttachObject(ponyEnt); ponyNode.Position = new Vector3(0, 0, 0); ponyEnt.SetMaterialName("BgPony"); wingsEnt = sceneMgr.CreateEntity("BgPonyColtWings.mesh"); wingsEnt.SetMaterialName("BgPonyWings"); hornEnt = sceneMgr.CreateEntity("BgPonyHorn.mesh"); hornEnt.SetMaterialName("BgPonyHorn"); eyesEnt = sceneMgr.CreateEntity("BgPonyColtEyes.mesh"); eyesEnt.SetMaterialName("BgPonyEyes"); foldedWingsEnt = sceneMgr.CreateEntity("BgPonyColtWingsFolded.mesh"); foldedWingsEnt.SetMaterialName("BgPonyWingsFolded"); hairEnts = new Entity[NUMBER_OF_HAIRSTYLES]; maneEnts = new Entity[NUMBER_OF_HAIRSTYLES]; tailEnts = new Entity[NUMBER_OF_HAIRSTYLES]; for (int a = 0; a < NUMBER_OF_HAIRSTYLES; a++) { hairEnts[a] = sceneMgr.CreateEntity("BgPonyHair" + (a + 1) + ".mesh"); hairEnts[a].SetMaterialName("BgPonyHair_Double_" + (a + 1)); maneEnts[a] = sceneMgr.CreateEntity("BgPonyMane" + (a + 1) + ".mesh"); maneEnts[a].SetMaterialName("BgPonyHair_Double_" + (a + 1)); tailEnts[a] = sceneMgr.CreateEntity("BgPonyTail" + (a + 1) + ".mesh"); tailEnts[a].SetMaterialName("BgPonyHair_Double_" + (a + 1)); } wingsEnt.Visible = false; foldedWingsEnt.Visible = false; hornEnt.Visible = false; for (int a = 1; a < NUMBER_OF_HAIRSTYLES; a++) { hairEnts[a].Visible = false; maneEnts[a].Visible = false; tailEnts[a].Visible = false; } AdjustBodyColour(bodyColour); AdjustBodyAOColour(bodyAOColour); AdjustHairColour1(hairColour1); AdjustHairColour2(hairColour2); AdjustHairAOColour1(hairAOColour1); AdjustHairAOColour2(hairAOColour2); // attach stuff ponyEnt.AttachObjectToBone("Eyes", eyesEnt); ponyEnt.AttachObjectToBone("Horn", hornEnt); ponyEnt.AttachObjectToBone("Wings", wingsEnt); ponyEnt.AttachObjectToBone("Wings", foldedWingsEnt); for (int a = 0; a < NUMBER_OF_HAIRSTYLES; a++) { ponyEnt.AttachObjectToBone("Hair", hairEnts[a]); ponyEnt.AttachObjectToBone("Mane", maneEnts[a]); ponyEnt.AttachObjectToBone("Tail", tailEnts[a]); } // setup animations Skeleton skeleton = ponyEnt.Skeleton; skeleton.BlendMode = SkeletonAnimationBlendMode.ANIMBLEND_CUMULATIVE; // set up the blink animation state with some stuff blinkState = ponyEnt.GetAnimationState("Blink2"); blinkState.Enabled = true; blinkState.Loop = true; blinkState.Weight = 1; blinkState.CreateBlendMask(skeleton.NumBones, 0f); ushort handle = skeleton.GetBone("EyeBrowTop.R").Handle; blinkState.SetBlendMaskEntry(handle, 1f); handle = skeleton.GetBone("EyeBrowBottom.R").Handle; blinkState.SetBlendMaskEntry(handle, 1f); handle = skeleton.GetBone("EyeBrowTop.L").Handle; blinkState.SetBlendMaskEntry(handle, 1f); handle = skeleton.GetBone("EyeBrowBottom.L").Handle; blinkState.SetBlendMaskEntry(handle, 1f); animState = ponyEnt.GetAnimationState("Stand1"); wingsState = wingsEnt.GetAnimationState("Flap1"); maneStates = new AnimationState[NUMBER_OF_HAIRSTYLES]; tailStates = new AnimationState[NUMBER_OF_HAIRSTYLES]; for (int a = 0; a < NUMBER_OF_HAIRSTYLES; a++) { maneStates[a] = maneEnts[a].GetAnimationState("Stand1"); tailStates[a] = tailEnts[a].GetAnimationState("Stand1"); maneStates[a].Enabled = tailStates[a].Enabled = true; maneStates[a].Loop = tailStates[a].Loop = true; } currentAnimation = "Stand1"; animState.Enabled = wingsState.Enabled = true; animState.Loop = wingsState.Loop = true; }
// Just override the mandatory create scene method public override void CreateScene() { // Set ambient light sceneMgr.AmbientLight = new ColourValue(0.2f, 0.2f, 0.2f); // Skybox sceneMgr.SetSkyBox(true, "Examples/MorningSkyBox"); // Create a light Light l = sceneMgr.CreateLight("MainLight"); l.Type = Light.LightTypes.LT_DIRECTIONAL; Vector3 dir = new Vector3(0.5f, -1, 0); dir.Normalise(); l.Direction = dir; l.DiffuseColour = new ColourValue(1.0f, 1.0f, 0.8f); l.SpecularColour= new ColourValue(1.0f, 1.0f, 1.0f); // Create a prefab plane mPlane = new MovablePlane(Vector3.UNIT_Y, 0); MeshManager.Singleton.CreatePlane("ReflectionPlane", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, mPlane._getDerivedPlane(), 2000, 2000, 1, 1, true, 1, 1, 1, Vector3.UNIT_Z); mPlaneEnt = sceneMgr.CreateEntity( "Plane", "ReflectionPlane" ); // Create an entity from a model (will be loaded automatically) Entity knotEnt = sceneMgr.CreateEntity("Knot", "knot.mesh"); // Create an entity from a model (will be loaded automatically) Entity ogreHead = sceneMgr.CreateEntity("Head", "ogrehead.mesh"); knotEnt.SetMaterialName("Examples/TextureEffect2"); // Attach the rtt entity to the root of the scene SceneNode rootNode = sceneMgr.RootSceneNode; mPlaneNode = rootNode.CreateChildSceneNode(); // Attach both the plane entity, and the plane definition mPlaneNode.AttachObject(mPlaneEnt); mPlaneNode.AttachObject(mPlane); mPlaneNode.Translate(0, -10, 0); // Tilt it a little to make it interesting mPlaneNode.Roll(new Degree(5)); rootNode.CreateChildSceneNode( "Head" ).AttachObject( ogreHead ); TexturePtr texture = TextureManager.Singleton.CreateManual( "RttTex", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME, TextureType.TEX_TYPE_2D, 512, 512, 0, PixelFormat.PF_R8G8B8, (int) TextureUsage.TU_RENDERTARGET ); RenderTarget rttTex = texture.GetBuffer().GetRenderTarget(); mReflectCam = sceneMgr.CreateCamera("ReflectCam"); mReflectCam.NearClipDistance = camera.NearClipDistance; mReflectCam.FarClipDistance = camera.FarClipDistance; mReflectCam.AspectRatio = (float)window.GetViewport(0).ActualWidth / (float)window.GetViewport(0).ActualHeight; mReflectCam.FOVy = camera.FOVy; Viewport v = rttTex.AddViewport( mReflectCam ); v.SetClearEveryFrame(true); v.BackgroundColour = ColourValue.Black; MaterialPtr mat = MaterialManager.Singleton.Create("RttMat", ResourceGroupManager.DEFAULT_RESOURCE_GROUP_NAME); TextureUnitState t = mat.GetTechnique(0).GetPass(0).CreateTextureUnitState("RustedMetal.jpg"); t = mat.GetTechnique(0).GetPass(0).CreateTextureUnitState("RttTex"); // Blend with base texture t.SetColourOperationEx(LayerBlendOperationEx.LBX_BLEND_MANUAL, LayerBlendSource.LBS_TEXTURE, LayerBlendSource.LBS_CURRENT, ColourValue.White, ColourValue.White, 0.25f); t.SetTextureAddressingMode(TextureUnitState.TextureAddressingMode.TAM_CLAMP); t.SetProjectiveTexturing(true, mReflectCam); rttTex.PostRenderTargetUpdate += postRenderTargetUpdate; rttTex.PreRenderTargetUpdate += preRenderTargetUpdate; // set up linked reflection mReflectCam.EnableReflection(mPlane); // Also clip mReflectCam.EnableCustomNearClipPlane(mPlane); // Give the plane a texture mPlaneEnt.SetMaterialName("RttMat"); // Add a whole bunch of extra transparent entities Entity cloneEnt; for (int n = 0; n < 10; ++n) { // Create a new node under the root SceneNode node = sceneMgr.CreateSceneNode(); // Random translate Vector3 nodePos; nodePos.x = Mogre.Math.SymmetricRandom() * 750.0f; nodePos.y = Mogre.Math.SymmetricRandom() * 100.0f + 25; nodePos.z = Mogre.Math.SymmetricRandom() * 750.0f; node.Position = nodePos; rootNode.AddChild(node); // Clone knot string cloneName = "Knot" + n; cloneEnt = knotEnt.Clone(cloneName); // Attach to new node node.AttachObject(cloneEnt); } camera.Position = new Vector3(-50, 100, 500); camera.LookAt(0,0,0); }