public AttachObject ( Axiom.Core.MovableObject obj ) : void | ||
obj | Axiom.Core.MovableObject | |
return | void |
protected override void CreateScene() { viewport.BackgroundColor = ColorEx.White; scene.AmbientLight = new ColorEx(0.5f, 0.5f, 0.5f); Light light = scene.CreateLight("MainLight"); light.Position = new Vector3(20, 80, 50); light.Diffuse = ColorEx.Blue; scene.LoadWorldGeometry("Terrain.xml"); scene.SetFog(FogMode.Exp2, ColorEx.White, .008f, 0, 250); // water plane setup Plane waterPlane = new Plane(Vector3.UnitY, 1.5f); MeshManager.Instance.CreatePlane( "WaterPlane", waterPlane, 2800, 2800, 20, 20, true, 1, 10, 10, Vector3.UnitZ); Entity waterEntity = scene.CreateEntity("Water", "WaterPlane"); waterEntity.MaterialName = "Terrain/WaterPlane"; waterNode = scene.RootSceneNode.CreateChildSceneNode("WaterNode"); waterNode.AttachObject(waterEntity); waterNode.Translate(new Vector3(1000, 0, 1000)); }
public MultiLights(SceneManager pSceneManager, SceneNode pCamNode, MovingObject pPlayerShip, Int32 pNumberOfLights) { oldCamLightColor = CamLightColor = new ColorEx(0.13f, 0.1f, 0.05f); PlayerLightColor = ColorEx.White; camLights = new List<Light>(pNumberOfLights); innerLights = (Int32)Math.Round(pNumberOfLights / 3.0f, MidpointRounding.AwayFromZero); outerLights = pNumberOfLights - innerLights; // create the playership's light. playerLight = pSceneManager.CreateLight("playerSpotLight"); playerLight.Type = LightType.Spotlight; playerLight.Diffuse = PlayerLightColor; playerLight.Specular = ColorEx.White; playerLight.SetSpotlightRange(0.0f, 120.0f); playerLight.Direction = Vector3.NegativeUnitZ; playerLightNode = pPlayerShip.Node.CreateChildSceneNode(); playerLightNode.AttachObject(playerLight); playerLightNode.Position = new Vector3(0, 0, 0); playerLightNode.SetDirection(new Vector3(1, 0, 0), TransformSpace.Local); // create the camera spotlights around the camera's direction. camInnerLightNode = pCamNode.CreateChildSceneNode(); camInnerLightNode.Position = new Vector3(0, 0, 0); camOuterLightNode = pCamNode.CreateChildSceneNode(); camOuterLightNode.Position = new Vector3(0, 0, 0); for (var i = 0; i < innerLights; i++) { var light = pSceneManager.CreateLight("camInnerLight " + (i + 1)); light.Type = LightType.Spotlight; light.Diffuse = CamLightColor; light.Specular = ColorEx.White; light.SetSpotlightRange(0.0f, 25.0f); light.Direction = Quaternion.FromAngleAxis(360.0 * i / innerLights * Constants.DegreesToRadians, Vector3.UnitZ) * Quaternion.FromAngleAxis(10.0 * Constants.DegreesToRadians, Vector3.UnitX) * Vector3.NegativeUnitZ; camLights.Add(light); camInnerLightNode.AttachObject(light); } for (var i = 0; i < outerLights; i++) { var light = pSceneManager.CreateLight("camOuterLight " + (i + 1)); light.Type = LightType.Spotlight; light.Diffuse = CamLightColor; light.Specular = ColorEx.White; light.SetSpotlightRange(0.0f, 25.0f); light.Direction = Quaternion.FromAngleAxis(360.0 * i / outerLights * Constants.DegreesToRadians, Vector3.UnitZ) * Quaternion.FromAngleAxis(20.0 * Constants.DegreesToRadians, Vector3.UnitX) * Vector3.NegativeUnitZ; camLights.Add(light); camOuterLightNode.AttachObject(light); } }
public void CreateScene() { _entity = _root.SceneManager.CreateEntity("BasicCube", PrefabEntity.Cube); _entity.MaterialName = "Examples/TestImage"; _sceneNode = Root.Instance.SceneManager.RootSceneNode.CreateChildSceneNode(); _sceneNode.Position = new Vector3(150, 0, -300); _sceneNode.AttachObject(_entity); _sceneNode.Yaw(45); }
public override void CreateScene() { scene.AmbientLight = new ColorEx( .4f, .4f, .4f ); Light light = scene.CreateLight( "MainLight" ); light.Position = new Vector3( 50, 80, 0 ); Entity head = scene.CreateEntity( "OgreHead", "ogrehead.mesh" ); entityList.Add( head ); scene.RootSceneNode.CreateChildSceneNode().AttachObject( head ); Entity box = scene.CreateEntity( "Box1", "cube.mesh" ); entityList.Add( box ); scene.RootSceneNode.CreateChildSceneNode( new Vector3( -100, 0, 0 ), Quaternion.Identity ).AttachObject( box ); box = scene.CreateEntity( "Box2", "cube.mesh" ); entityList.Add( box ); scene.RootSceneNode.CreateChildSceneNode( new Vector3( 100, 0, -300 ), Quaternion.Identity ).AttachObject( box ); box = scene.CreateEntity( "Box3", "cube.mesh" ); entityList.Add( box ); scene.RootSceneNode.CreateChildSceneNode( new Vector3( -200, 100, -200 ), Quaternion.Identity ).AttachObject( box ); frustum = new Frustum( "PlayFrustum" ); frustum.Near = 10; frustum.Far = 300; // create a node for the frustum and attach it frustumNode = scene.RootSceneNode.CreateChildSceneNode( new Vector3( 0, 0, 200 ), Quaternion.Identity ); // set the camera in a convenient position camera.Position = new Vector3( 0, 759, 680 ); camera.LookAt( Vector3.Zero ); frustumNode.AttachObject( frustum ); frustumNode.AttachObject( camera2 ); }
public override void CreateScene() { // set some ambient light scene.AmbientLight = new ColorEx( 1.0f, 0.2f, 0.2f, 0.2f ); // create a skydome scene.SetSkyDome( true, "Examples/CloudySky", 5, 8 ); // create a simple default point light Light light = scene.CreateLight( "MainLight" ); light.Position = new Vector3( 20, 80, 50 ); // create a plane for the plane mesh Plane plane = new Plane(); plane.Normal = Vector3.UnitY; plane.D = 200; // create a plane mesh MeshManager.Instance.CreatePlane( "FloorPlane", ResourceGroupManager.DefaultResourceGroupName, plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ ); // create an entity to reference this mesh Entity planeEntity = scene.CreateEntity( "Floor", "FloorPlane" ); planeEntity.MaterialName = "Examples/RustySteel"; scene.RootSceneNode.CreateChildSceneNode().AttachObject( planeEntity ); // create an entity to have follow the path Entity ogreHead = scene.CreateEntity( "OgreHead", "ogrehead.mesh" ); // create a scene node for the entity and attach the entity headNode = scene.RootSceneNode.CreateChildSceneNode( "OgreHeadNode", Vector3.Zero, Quaternion.Identity ); headNode.AttachObject( ogreHead ); // make sure the camera tracks this node camera.SetAutoTracking( true, headNode, Vector3.Zero ); // create a scene node to attach the camera to SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode( "CameraNode" ); cameraNode.AttachObject( camera ); // turn on some fog scene.SetFog( FogMode.Exp, ColorEx.White, 0.0002f ); }
public void CreateScene() { //ManualObject manual = _root.SceneManager.CreateManualObject("TEST"); _entity = _root.SceneManager.CreateEntity("CubeBrowser", PrefabEntity.Cube); _sceneNode = Root.Instance.SceneManager.RootSceneNode.CreateChildSceneNode(); _sceneNode.AttachObject(_entity); //_sceneNode.Yaw(45); _sceneNode.Position = new Vector3(0, 0, -300); _sceneNode.Scale = new Vector3(5, 4, 4); TextureUtil.CreateDynamicTextureAndMaterial( "CBDynamicTexture", "CBDynamicMaterial", _browserWidth, _browserHeight, out _texture, out _material); _entity.MaterialName = "CBDynamicMaterial"; Core.BrowserManager.BrowserRenderEvent += new BrowserRenderEventHandler(BrowserManager_BrowserRenderEvent); _browserId = Core.BrowserManager.CreateBrowser("http://www.google.com.au", _browserWidth, _browserHeight); CreateOverlay(); }
public void AddToScene(Vector3 position, Vector3 scale, Quaternion rotation) { string uniqueName = WorldEditor.GetUniqueName(name, type); if (!String.Equals(type, "Drag")) { this.uniName = uniqueName; nameDictionary.Add(uniqueName, parent); } entity = scene.CreateEntity(uniqueName, this.MeshName); entity.CastShadows = castShadows; node = scene.RootSceneNode.CreateChildSceneNode(position); node.ScaleFactor = scale; node.Orientation = rotation; node.AttachObject(entity); ValidateSubMeshList(); AddCollisionObject(); //subMeshCollection.Changed += new SubMeshChangeEventHandler(subMeshCollection_Changed); }
public void Init( ref SceneNode ParentSceneNode, int tableX, int tableZ, int tileX, int tileZ ) { init = true; Vector3 ParentPos = ParentSceneNode.DerivedPosition; info.PageX = tableX; info.PageZ = tableZ; info.TileX = tileX; info.TileZ = tileZ; // Calculate the offset from the parent for this tile Vector3 scale = Options.Instance.Scale; float endx = Options.Instance.TileSize * scale.x; float endz = Options.Instance.TileSize * scale.z; info.PosX = info.TileX * endx; info.PosZ = info.TileZ * endz; name = String.Format("tile[{0},{1}][{2},{3}]",info.PageX, info.PageZ, info.TileX, info.TileZ); tileSceneNode = (SceneNode)ParentSceneNode.CreateChild( name ); // figure out scene node position within parent tileSceneNode.Position = new Vector3( info.PosX, 0, info.PosZ ); tileSceneNode.AttachObject( this ); float MaxHeight = Data2DManager.Instance.GetMaxHeight(info.PageX, info.PageZ); bounds.SetExtents( new Vector3(0,0,0) , new Vector3((float)( endx ), MaxHeight, (float)( endz )) ); //Change Zone of this page boundsExt.SetExtents( new Vector3( - endx * 0.5f, - MaxHeight * 0.5f, - endz * 0.5f) , new Vector3(endx * 1.5f, MaxHeight * 1.5f , endz * 1.5f)); //Change Zone of this page this.worldAABB.SetExtents( new Vector3(info.PosX + ParentPos.x ,0, info.PosZ + ParentPos.z), new Vector3((float)( info.PosX + ParentPos.x + endx), MaxHeight, (float)( info.PosZ + ParentPos.z + endz) )); //this.worldBounds.SetExtents( new Vector3(info.PosX + ParentPos.x ,0, info.PosZ + ParentPos.z), new Vector3((float)( info.PosX + ParentPos.x + endx), MaxHeight, (float)( info.PosZ + ParentPos.z + endz) )); for ( long i = 0; i < 4; i++ ) { neighbors[ i ] = null; } //force update in scene node //tileSceneNode.update( true, true ); tileSceneNode.NeedUpdate(); loaded = false; }
/// <summary> /// /// </summary> /// <param name="sceneMgr"></param> private void SetupBody( SceneManager sceneMgr ) { // create main model bodyNode = sceneMgr.RootSceneNode.CreateChildSceneNode( Vector3.UnitY * CharHeight ); bodyEnt = sceneMgr.CreateEntity( "SinbadBody", "Sinbad.mesh" ); bodyNode.AttachObject( bodyEnt ); // create swords and attach to sheath sword1 = sceneMgr.CreateEntity( "SinbadSword1", "Sword.mesh" ); sword2 = sceneMgr.CreateEntity( "SinbadSword2", "Sword.mesh" ); bodyEnt.AttachObjectToBone( "Sheath.L", sword1 ); bodyEnt.AttachObjectToBone( "Sheath.R", sword2 ); // create a couple of ribbon trails for the swords, just for fun NamedParameterList paras = new NamedParameterList(); paras[ "numberOfChains" ] = "2"; paras[ "maxElements" ] = "80"; swordTrail = (RibbonTrail)sceneMgr.CreateMovableObject( "SinbadRibbon", "RibbonTrail", paras ); swordTrail.MaterialName = "Examples/LightRibbonTrail"; swordTrail.TrailLength = 20; swordTrail.IsVisible = false; sceneMgr.RootSceneNode.AttachObject( swordTrail ); for ( int i = 0; i < 2; i++ ) { swordTrail.SetInitialColor( i, new ColorEx( 1, 0.8f, 0 ) ); swordTrail.SetColorChange( i, new ColorEx( 0.75f, 0.25f, 0.25f, 0.25f ) ); swordTrail.SetWidthChange( i, 1 ); swordTrail.SetInitialWidth( i, 0.5f ); } keyDirection = Vector3.Zero; verticalVelocity = 0; }
public NameWidget(SceneNode node, string name) : base(name) { this.node = node; textBillboard = new TextBillboardSet("NameBar/" + name); node.AttachObject(textBillboard); Renderer tmp = GuiSystem.Instance.Renderer; Debug.Assert(tmp is MultiverseRenderer, "Not using multiverse renderer"); renderer = (MultiverseRenderer)tmp; }
protected override void CreateScene() { // set some ambient light scene.AmbientLight = new ColorEx(1.0f, 0.2f, 0.2f, 0.2f); // create a skydome scene.SetSkyDome(true, "Examples/CloudySky", 5, 8); // create a simple default point light Light light = scene.CreateLight("MainLight"); light.Position = new Vector3(20, 80, 50); // create a plane for the plane mesh Plane plane = new Plane(); plane.Normal = Vector3.UnitY; plane.D = 200; // create a plane mesh MeshManager.Instance.CreatePlane("FloorPlane", plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ); // create an entity to reference this mesh Entity planeEntity = scene.CreateEntity("Floor", "FloorPlane"); planeEntity.MaterialName = "Examples/RustySteel"; scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity); // create an entity to have follow the path Entity ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh"); // create a scene node for the entity and attach the entity headNode = scene.RootSceneNode.CreateChildSceneNode("OgreHeadNode", Vector3.Zero, Quaternion.Identity); headNode.AttachObject(ogreHead); // make sure the camera tracks this node camera.SetAutoTracking(true, headNode, Vector3.Zero); // create a scene node to attach the camera to SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode("CameraNode"); cameraNode.AttachObject(camera); // create new animation Animation animation = scene.CreateAnimation("OgreHeadAnimation", 10.0f); // nice smooth animation animation.InterpolationMode = InterpolationMode.Spline; // create the main animation track NodeAnimationTrack track = animation.CreateNodeTrack(0, cameraNode); // create a few keyframes to move the camera around AddKey(track, 0.0f, Vector3.Zero); AddKey(track, 2.5f, new Vector3(500, 500, -1000)); AddKey(track, 5.0f, new Vector3(-1500, 1000, -600)); AddKey(track, 7.5f, new Vector3(0, -100, 0)); AddKey(track, 10.0f, Vector3.Zero); // create a new animation state to control the animation animationState = scene.CreateAnimationState("OgreHeadAnimation"); // enable the animation animationState.IsEnabled = true; // turn on some fog scene.SetFog(FogMode.Exp, ColorEx.White, 0.0002f); }
public Forest(SceneNode parentSceneNode, XmlTextReader r) { FromXML(r); // create a scene node if (parentSceneNode == null) { parentSceneNode = TerrainManager.Instance.RootSceneNode; } this.parentSceneNode = parentSceneNode; parentSceneNode.AttachObject(this); box = AxisAlignedBox.Null; CastShadows = true; }
public Forest(int seed, String name, SceneNode parentSceneNode) { this.seed = seed; this.name = name; // create a scene node if (parentSceneNode == null) { parentSceneNode = TerrainManager.Instance.RootSceneNode; } this.parentSceneNode = parentSceneNode; parentSceneNode.AttachObject(this); box = AxisAlignedBox.Null; CastShadows = true; }
protected override void CreateScene() { // initialise the SoundManager by setting the RenderWindow SoundManager.Instance.SetRenderWindow(this.window, this.camera); int back_id = SoundManager.Instance.PreLoadSound("background.wav", Sound.SIMPLE_SOUND); // set some ambient light scene.AmbientLight = new ColorEx(1.0f, 0.2f, 0.2f, 0.2f); // create a skydome scene.SetSkyDome(true, "Examples/CloudySky", 5, 8); // create a simple default point light Light light = scene.CreateLight("MainLight"); light.Position = new Vector3(20, 80, 50); // create a plane for the plane mesh Plane plane = new Plane(); plane.Normal = Vector3.UnitY; plane.D = 200; // create a plane mesh MeshManager.Instance.CreatePlane("FloorPlane", plane, 200000, 200000, 20, 20, true, 1, 50, 50, Vector3.UnitZ); // create an entity to reference this mesh Entity planeEntity = scene.CreateEntity("Floor", "FloorPlane"); planeEntity.MaterialName = "Examples/RustySteel"; scene.RootSceneNode.CreateChildSceneNode().AttachObject(planeEntity); // create an entity to have follow the path Entity ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh"); // create a scene node for the entity and attach the entity headNode = scene.RootSceneNode.CreateChildSceneNode("OgreHeadNode", Vector3.Zero, Quaternion.Identity); headNode.AttachObject(ogreHead); // make sure the camera tracks this node //camera.SetAutoTracking(true, headNode, Vector3.Zero); // create a scene node to attach the camera to SceneNode cameraNode = scene.RootSceneNode.CreateChildSceneNode("CameraNode"); cameraNode.AttachObject(camera); /////////////////////////- AGE Sound Library Settings -////////////////////////// SoundManager.Instance.RolloffFactor = 0.01f; // we're working on a large scale growl = SoundManager.Instance.LoadSound("growl.ogg", Sound.THREED_SOUND); Sound back = SoundManager.Instance.GetSound( back_id ); // load a simple sound //Sound back = SoundManager.Instance.LoadSound("background.wav", Sound.SIMPLE_SOUND); // set the volume low back.Volume = -2000; // play the simple sound in a loop back.Play(true); // load a 3D sound // attach the sound to the head headNode.AttachObject(growl); // set the sound's properties growl.ConeAngles = new int[]{120, 120}; growl.ConeDirection = Vector3.UnitZ; //growl.MaxDistance = 5000; growl.OutsideVolume = -10000; // play the 3D sound in a loop growl.Play(true); //////////////////////////////////////////////////////////////////////////////// // create new animation Animation animation = scene.CreateAnimation("OgreHeadAnimation", 10.0f); // nice smooth animation animation.InterpolationMode = InterpolationMode.Spline; // create the main animation track AnimationTrack track = animation.CreateTrack(0, cameraNode); // create a few keyframes to move the camera around KeyFrame frame = track.CreateKeyFrame(0.0f); frame = track.CreateKeyFrame(2.5f); frame.Translate = new Vector3(500, 500, -1000); frame = track.CreateKeyFrame(5.0f); frame.Translate = new Vector3(-1500, 1000, -600); frame = track.CreateKeyFrame(7.5f); frame.Translate = new Vector3(0, -100, 0); frame = track.CreateKeyFrame(10.0f); frame.Translate = Vector3.Zero; // create a new animation state to control the animation animationState = scene.CreateAnimationState("OgreHeadAnimation"); // enable the animation animationState.IsEnabled = true; // turn on some fog scene.SetFog(FogMode.Exp, ColorEx.White, 0.0002f); }
private void AddToScene() { string sceneName = WorldEditor.GetUniqueName(name, "Particle System"); particleSystem = ParticleSystemManager.Instance.CreateSystem(sceneName, particleSystemName); particleSystem.ScaleVelocity(velocityScale); baseHeight = particleSystem.DefaultHeight; baseWidth = particleSystem.DefaultWidth; ParticleScale = particleScale; if (attached) { Axiom.Animating.AttachmentPoint attachmentPoint = displayObject.GetAttachmentPoint(attachmentPointName); if (attachmentPoint == null) { attachmentPoint = new Axiom.Animating.AttachmentPoint(attachmentPointName, null, Quaternion.Identity, Vector3.Zero); } if (attachmentPoint.ParentBone != null) { tagPoint = displayObject.Entity.AttachObjectToBone(attachmentPoint.ParentBone, particleSystem, attachmentPoint.Orientation, attachmentPoint.Position); node = null; } else { node = scene.CreateSceneNode(); node.Position = attachmentPoint.Position; node.Orientation = attachmentPoint.Orientation; displayObject.SceneNode.AddChild(node); node.AttachObject(particleSystem); } } else { node = scene.RootSceneNode.CreateChildSceneNode(); node.AttachObject(particleSystem); node.Position = position; node.ScaleFactor = scale; node.Orientation = Quaternion.FromAngleAxis(rotation.y * MathUtil.RADIANS_PER_DEGREE, Vector3.UnitY); } }
public override void CreateScene() { // Check prerequisites first RenderSystemCapabilities caps = Root.Instance.RenderSystem.Capabilities; if ( !caps.HasCapability( Capabilities.VertexPrograms ) || !caps.HasCapability( Capabilities.FragmentPrograms ) ) { throw new AxiomException( "Your card does not support vertex and fragment programs, so cannot run this demo. Sorry!" ); } else { if ( !GpuProgramManager.Instance.IsSyntaxSupported( "arbfp1" ) && !GpuProgramManager.Instance.IsSyntaxSupported( "ps_2_0" ) ) { throw new AxiomException( "Your card does not support shader model 2, so cannot run this demo. Sorry!" ); } } scene.AmbientLight = ColorEx.Black; // create scene node mainNode = scene.RootSceneNode.CreateChildSceneNode(); // Load the meshes with non-default HBU options for ( int mn = 0; mn < NUM_ENTITIES; mn++ ) { Mesh mesh = MeshManager.Instance.Load( entityMeshes[ mn ], ResourceGroupManager.DefaultResourceGroupName, BufferUsage.DynamicWriteOnly, BufferUsage.StaticWriteOnly, true, true, 1 ); //so we can still read it // Build tangent vectors, all our meshes use only 1 texture coordset short srcIdx, destIdx; if ( !mesh.SuggestTangentVectorBuildParams( out srcIdx, out destIdx ) ) { mesh.BuildTangentVectors( srcIdx, destIdx ); } // Create entity entities[ mn ] = scene.CreateEntity( "Ent" + mn.ToString(), entityMeshes[ mn ] ); // Attach to child of root node mainNode.AttachObject( entities[ mn ] ); // Make invisible, except for index 0 if ( mn == 0 ) { entities[ mn ].MaterialName = materialNames[ currentEntity, currentMaterial ]; } else { entities[ mn ].IsVisible = false; } } for ( int i = 0; i < NUM_LIGHTS; i++ ) { lightPivots[ i ] = scene.RootSceneNode.CreateChildSceneNode(); lightPivots[ i ].Rotate( lightRotationAxes[ i ], lightRotationAngles[ i ] ); // Create a light, use default parameters lights[ i ] = scene.CreateLight( "Light" + i.ToString() ); lights[ i ].Position = lightPositions[ i ]; lights[ i ].Diffuse = diffuseLightColors[ i ]; lights[ i ].Specular = specularLightColors[ i ]; lights[ i ].IsVisible = lightState[ i ]; // Attach light lightPivots[ i ].AttachObject( lights[ i ] ); // Create billboard for light lightFlareSets[ i ] = scene.CreateBillboardSet( "Flare" + i.ToString() ); lightFlareSets[ i ].MaterialName = "Particles/Flare"; lightPivots[ i ].AttachObject( lightFlareSets[ i ] ); lightFlares[ i ] = lightFlareSets[ i ].CreateBillboard( lightPositions[ i ] ); lightFlares[ i ].Color = diffuseLightColors[ i ]; lightFlareSets[ i ].IsVisible = lightState[ i ]; } // move the camera a bit right and make it look at the knot camera.MoveRelative( new Vector3( 50, 0, 20 ) ); camera.LookAt( new Vector3( 0, 0, 0 ) ); // show overlay Overlay pOver = OverlayManager.Instance.GetByName( "Example/DP3Overlay" ); objectInfo = OverlayManager.Instance.Elements.GetElement( "Example/DP3/ObjectInfo" ); materialInfo = OverlayManager.Instance.Elements.GetElement( "Example/DP3/MaterialInfo" ); info = OverlayManager.Instance.Elements.GetElement( "Example/DP3/Info" ); objectInfo.Text = "Current: " + entityMeshes[ currentEntity ]; materialInfo.Text = "Current: " + materialNames[ currentEntity, currentMaterial ]; if ( !caps.HasCapability( Capabilities.FragmentPrograms ) ) { info.Text = "NOTE: Light colours and specular highlights are not supported by your card."; } pOver.Show(); }
public override void CreateScene() { // Register Compositor Logics CompositorManager.Instance.RegisterCompositorLogic( "HDR", new HdrLogic() ); scene.ShadowTechnique = ShadowTechnique.TextureModulative; scene.ShadowFarDistance = 1000; scene.AmbientLight = new ColorEx( 0.3f, 0.3f, 0.2f ); Light light = scene.CreateLight( "Light2" ); Vector3 dir = new Vector3( -1, -1, 0 ); dir.Normalize(); light.Type = LightType.Directional; light.Direction = dir; light.Diffuse = new ColorEx( 1.0f, 1.0f, 0.8f ); light.Specular = new ColorEx( 1.0f, 1.0f, 1.0f ); Entity entity; // House entity = scene.CreateEntity( "1", "tudorhouse.mesh" ); SceneNode n1 = scene.RootSceneNode.CreateChildSceneNode( new Vector3( 350, 450, -200 ) ); n1.AttachObject( entity ); entity = scene.CreateEntity( "2", "tudorhouse.mesh" ); SceneNode n2 = scene.RootSceneNode.CreateChildSceneNode( new Vector3( -350, 450, -200 ) ); n2.AttachObject( entity ); entity = scene.CreateEntity( "3", "knot.mesh" ); _spinny = scene.RootSceneNode.CreateChildSceneNode( new Vector3( 0, 0, 300 ) ); _spinny.AttachObject( entity ); entity.MaterialName = "Examples/MorningCubeMap"; scene.SetSkyBox( true, "Examples/MorningSkyBox", 50 ); Plane plane = new Plane(); plane.Normal = Vector3.UnitY; plane.D = 100; MeshManager.Instance.CreatePlane( "Myplane", ResourceGroupManager.DefaultResourceGroupName, plane, 1500, 1500, 10, 10, true, 1, 5, 5, Vector3.UnitZ ); Entity planeEntity = scene.CreateEntity( "plane", "Myplane" ); planeEntity.MaterialName = "Examples/Rockwall"; planeEntity.CastShadows = false; scene.RootSceneNode.CreateChildSceneNode().AttachObject( planeEntity ); camera.Position = new Vector3( -400, 50, 900 ); camera.LookAt( new Vector3( 0, 80, 0 ) ); /// Create a couple of hard coded postfilter effects as an example of how to do it /// but the preferred method is to use compositor scripts. _createEffects(); foreach ( string name in _compositorList ) { CompositorManager.Instance.AddCompositor( this.window.GetViewport( 0 ), name ); } //CompositorManager.Instance.SetCompositorEnabled(this.window.GetViewport(0), // _compositorList[_compositorList.Length - 2], // true); CompositorManager.Instance.SetCompositorEnabled( this.window.GetViewport( 0 ), _compositorList[ 0 ], true ); }
protected override void CreateScene() { scene.AmbientLight = ColorEx.Black; // create scene node mainNode = scene.RootSceneNode.CreateChildSceneNode(); // Load the meshes with non-default HBU options for(int mn = 0; mn < entityMeshes.Length; mn++) { Mesh mesh = MeshManager.Instance.Load(entityMeshes[mn], BufferUsage.DynamicWriteOnly, BufferUsage.StaticWriteOnly, true, true, 1); //so we can still read it // Build tangent vectors, all our meshes use only 1 texture coordset short srcIdx, destIdx; if (!mesh.SuggestTangentVectorBuildParams(out srcIdx, out destIdx)) { mesh.BuildTangentVectors(srcIdx, destIdx); } // Create entity entities[mn] = scene.CreateEntity("Ent" + mn.ToString(), entityMeshes[mn]); // Attach to child of root node mainNode.AttachObject(entities[mn]); // Make invisible, except for index 0 if (mn == 0) { entities[mn].MaterialName = materialNames[currentMaterial]; } else { entities[mn].IsVisible = false; } } for (int i = 0; i < NUM_LIGHTS; i++) { lightPivots[i] = scene.RootSceneNode.CreateChildSceneNode(); lightPivots[i].Rotate(lightRotationAxes[i], lightRotationAngles[i]); // Create a light, use default parameters lights[i] = scene.CreateLight("Light" + i.ToString()); lights[i].Position = lightPositions[i]; lights[i].Diffuse = diffuseLightColors[i]; lights[i].Specular = specularLightColors[i]; lights[i].IsVisible = lightState[i]; // Attach light lightPivots[i].AttachObject(lights[i]); // Create billboard for light lightFlareSets[i] = scene.CreateBillboardSet("Flare" + i.ToString()); lightFlareSets[i].MaterialName = "Particles/Flare"; lightPivots[i].AttachObject(lightFlareSets[i]); lightFlares[i] = lightFlareSets[i].CreateBillboard(lightPositions[i]); lightFlares[i].Color = diffuseLightColors[i]; lightFlareSets[i].IsVisible = lightState[i]; } // move the camera a bit right and make it look at the knot camera.MoveRelative(new Vector3(50, 0, 20)); camera.LookAt(new Vector3(0, 0, 0)); }
public void Build( bool stencilShadows, int logLevel ) { // Create a node node = sceneMgr.RootSceneNode.CreateChildSceneNode( name, center ); node.AttachObject( this ); // We need to create enough LOD buckets to deal with the highest LOD // we encountered in all the meshes queued for ( ushort lod = 0; lod < lodValues.Count; ++lod ) { LODBucket lodBucket = new LODBucket( this, lod, (float)lodValues[ lod ] ); lodBucketList.Add( lodBucket ); // Now iterate over the meshes and assign to LODs // LOD bucket will pick the right LOD to use IEnumerator iter = queuedSubMeshes.GetEnumerator(); while ( iter.MoveNext() ) { QueuedSubMesh qsm = (QueuedSubMesh)iter.Current; lodBucket.Assign( qsm, lod ); } // now build lodBucket.Build( stencilShadows, logLevel ); } // Do we need to build an edge list? if ( stencilShadows ) { EdgeListBuilder eb = new EdgeListBuilder(); //int vertexSet = 0; foreach ( LODBucket lod in lodBucketList ) { foreach ( MaterialBucket mat in lod.MaterialBucketMap.Values ) { // Check if we have vertex programs here Technique t = mat.Material.GetBestTechnique(); if ( null != t ) { Pass p = t.GetPass( 0 ); if ( null != p ) { if ( p.HasVertexProgram ) { vertexProgramInUse = true; } } } foreach ( GeometryBucket geom in mat.GeometryBucketList ) { // Check we're dealing with 16-bit indexes here // Since stencil shadows can only deal with 16-bit // More than that and stencil is probably too CPU-heavy // in any case if ( geom.IndexData.indexBuffer.Type != IndexType.Size16 ) { throw new AxiomException( "Only 16-bit indexes allowed when using stencil shadows" ); } eb.AddVertexData( geom.VertexData ); eb.AddIndexData( geom.IndexData ); } } } edgeList = eb.Build(); } }
protected override void SetupContent() { SceneManager.SetSkyBox( true, "Examples/StormySkyBox", 5000 ); // add a skybox // setup some basic lighting for our scene SceneManager.AmbientLight = new ColorEx( 0.5f, 0.5f, 0.5f ); SceneManager.CreateLight( "DynTexLight1" ).Position = new Vector3( 20, 80, 50 ); // set initial camera position CameraManager.setStyle( CameraStyle.Manual ); Camera.Position = new Vector3( 0, 0, 200 ); TrayManager.ShowCursor(); // create our dynamic texture with 8-bit luminance texels Texture tex = TextureManager.Instance.CreateManual( "thaw", ResourceGroupManager.DefaultResourceGroupName, TextureType.TwoD, TEXTURE_SIZE, TEXTURE_SIZE, 0, PixelFormat.L8, TextureUsage.DynamicWriteOnly ); mTexBuf = tex.GetBuffer(); // save off the texture buffer // initialise the texture to have full luminance mTexBuf.Lock( BufferLocking.Discard ); Memory.Set( mTexBuf.CurrentLock.Data, 0xff, mTexBuf.Size ); mTexBuf.Unlock(); // create a penguin and attach him to our penguin node Entity penguin = SceneManager.CreateEntity( "Penguin", "penguin.mesh" ); mPenguinNode = SceneManager.RootSceneNode.CreateChildSceneNode(); mPenguinNode.AttachObject( penguin ); // get and enable the penguin idle animation mPenguinAnimState = penguin.GetAnimationState( "amuse" ); mPenguinAnimState.IsEnabled = true; // create a snowstorm over the scene, and fast forward it a little ParticleSystem ps = ParticleSystemManager.Instance.CreateSystem( "Snow", "Examples/Snow" ); SceneManager.RootSceneNode.AttachObject( ps ); ps.FastForward( 30 ); // create a frosted screen in front of the camera, using our dynamic texture to "thaw" certain areas Entity ent = SceneManager.CreateEntity( "Plane", PrefabEntity.Plane ); ent.MaterialName = "Examples/Frost"; SceneNode node = SceneManager.RootSceneNode.CreateChildSceneNode(); node.Position = new Vector3( 0, 0, 50 ); node.AttachObject( ent ); mPlaneSize = ent.BoundingBox.Size.x; // remember the size of the plane mCursorQuery = SceneManager.CreateRayQuery( new Ray() ); // create a ray scene query for the cursor mTimeSinceLastFreeze = 0; mWiping = false; }
public TerrainPage(Vector3 location, Page page) { this.location = location; pageCoord = new PageCoord(location, TerrainManager.Instance.PageSize); terrainMaterial = TerrainManager.Instance.TerrainMaterialConfig.NewTerrainMaterial(pageCoord.X, pageCoord.Z); currentPage = page; Debug.Assert(location == currentPage.Location, "creating TerrainPage with page at different location"); numTiles = currentPage.NumTiles; patchSize = TerrainManager.Instance.PageSize / numTiles; // set up the page height maps for this page of terrain subPageSize = TerrainManager.Instance.SubPageSize; int subPagesPerPage = TerrainManager.Instance.PageSize / subPageSize; pageHeightMap = new PageHeightMap(subPagesPerPage, TerrainManager.Instance.PageSize, TerrainManager.Instance.MaxMetersPerSample, TerrainManager.Instance.MinMetersPerSample); pageHeightMap.Location = location; // create and position a scene node for this terrain page string nodeName = String.Format("TerrainPage[{0},{1}]", (int)(location.x / TerrainManager.oneMeter), (int)(location.z / TerrainManager.oneMeter)); // DEBUG - Console.WriteLine("Creating {0}", name); sceneNode = TerrainManager.Instance.WorldRootSceneNode.CreateChildSceneNode(nodeName); sceneNode.Position = location; sceneNode.AttachObject(this); // create the render operation renderOp = new RenderOperation(); renderOp.operationType = OperationType.TriangleList; renderOp.useIndices = true; CreatePatches(); SetCastShadows(); UpdateBounds(); TerrainManager.Instance.ShadowConfig.ShadowTechniqueChange += ShadowTechniqueChangeHandler; }
public virtual Matrix4 GetSpotlightViewProjMatrix( int index ) { if ( index < Config.MaxSimultaneousLights ) { Light l = GetLight( index ); if ( l != this.blankLight && l.Type == LightType.Spotlight && this.spotlightViewProjMatrixDirty[ index ] ) { var frust = new Frustum(); var dummyNode = new SceneNode( null ); dummyNode.AttachObject( frust ); frust.ProjectionType = Projection.Perspective; frust.FieldOfView = l.SpotlightOuterAngle; frust.AspectRatio = 1.0f; // set near clip the same as main camera, since they are likely // to both reflect the nature of the scene frust.Near = this.currentCamera.Near; // Calculate position, which same as spotlight position, in camera-relative coords if required dummyNode.Position = l.GetDerivedPosition( true ); // Calculate direction, which same as spotlight direction Vector3 dir = -l.DerivedDirection; // backwards since point down -z dir.Normalize(); Vector3 up = Vector3.UnitY; // Check it's not coincident with dir if ( Math.Utility.Abs( up.Dot( dir ) ) >= 1.0f ) { // Use camera up up = Vector3.UnitZ; } // cross twice to rederive, only direction is unaltered Vector3 left = dir.Cross( up ); left.Normalize(); up = dir.Cross( left ); up.Normalize(); // Derive quaternion from axes Quaternion q = Quaternion.FromAxes( left, up, dir ); dummyNode.Orientation = q; // The view matrix here already includes camera-relative changes if necessary // since they are built into the frustum position this.spotlightViewProjMatrix[ index ] = this.ProjectionClipSpace2DToImageSpacePerspective* frust.ProjectionMatrixRSDepth* frust.ViewMatrix; this.spotlightViewProjMatrixDirty[ index ] = false; } return this.spotlightViewProjMatrix[ index ]; } else { return Matrix4.Identity; } }
// Returns the number of geometry buckets public int Build(bool stencilShadows, bool logDetails) { int bucketCount = 0; // Create a node node = sceneMgr.RootSceneNode.CreateChildSceneNode(name, center); node.AttachObject(this); // We need to create enough LOD buckets to deal with the highest LOD // we encountered in all the meshes queued for (ushort lod = 0; lod < lodSquaredDistances.Count; ++lod) { LODBucket lodBucket = new LODBucket(this, lod, (float)lodSquaredDistances[lod]); lodBucketList.Add(lodBucket); // Now iterate over the meshes and assign to LODs // LOD bucket will pick the right LOD to use foreach (QueuedSubMesh qsm in queuedSubMeshes) { lodBucket.Assign(qsm, lod); } // now build bucketCount += lodBucket.Build(stencilShadows, logDetails); } // Do we need to build an edge list? if (stencilShadows) { EdgeListBuilder eb = new EdgeListBuilder(); foreach (LODBucket lod in lodBucketList) { foreach (MaterialBucket mat in lod.MaterialBucketMap.Values) { // Check if we have vertex programs here Technique t = mat.Material.GetBestTechnique(); if (null != t) { Pass p = t.GetPass(0); if (null != p) { if (p.HasVertexProgram) { vertexProgramInUse = true; } } } foreach (GeometryBucket geom in mat.GeometryBucketList) { bucketCount++; // Check we're dealing with 16-bit indexes here // Since stencil shadows can only deal with 16-bit // More than that and stencil is probably too CPU-heavy // in any case if (geom.IndexData.indexBuffer.Type != IndexType.Size16) { throw new AxiomException("Only 16-bit indexes allowed when using stencil shadows"); } eb.AddVertexData(geom.VertexData); eb.AddIndexData(geom.IndexData); } } } edgeList = eb.Build(); } return(bucketCount); }
// Just override the mandatory create scene method public override void CreateScene() { RAND = new Random( 0 ); // najak: use a time-based seed GuiMgr = OverlayManager.Instance.Elements; scene.AmbientLight = new ColorEx( 0.75f, 0.75f, 0.75f ); // default Ambient Light // Customize Controls - speed up camera and slow down the input update rate this.camSpeed = 5.0f; inputInterval = inputTimer = 0.02f; // Create water mesh and entity, and attach to sceneNode waterMesh = new WaterMesh( "WaterMesh", PLANE_SIZE, CMPLX ); waterEntity = scene.CreateEntity( "WaterEntity", "WaterMesh" ); SceneNode waterNode = scene.RootSceneNode.CreateChildSceneNode(); waterNode.AttachObject( waterEntity ); // Add Ogre head, give it it's own node headNode = waterNode.CreateChildSceneNode(); Entity ent = scene.CreateEntity( "head", "ogrehead.mesh" ); headNode.AttachObject( ent ); // Create the camera node, set its position & attach camera camera.Yaw( -45f ); camera.Move( new Vector3( 1500f, 700f, PLANE_SIZE + 700f ) ); camera.LookAt( new Vector3( PLANE_SIZE / 2f, 300f, PLANE_SIZE / 2f ) ); camera.SetAutoTracking( false, headNode ); // Autotrack the head, but it isn't working right //scene.SetFog(FogMode.Exp, ColorEx.White, 0.000020f); // add Fog for fun, cuz we can // show overlay waterOverlay = OverlayManager.Instance.GetByName( "Example/WaterOverlay" ); waterOverlay.Show(); // Create Rain Emitter, but default Rain to OFF particleSystem = ParticleSystemManager.Instance.CreateSystem( "rain", "Examples/Water/Rain" ); particleEmitter = particleSystem.GetEmitter( 0 ); particleEmitter.EmissionRate = 0f; // Attach Rain Emitter to SceneNode, and place it 3000f above the water surface SceneNode rNode = scene.RootSceneNode.CreateChildSceneNode(); rNode.Translate( new Vector3( PLANE_SIZE / 2.0f, 3000, PLANE_SIZE / 2.0f ) ); rNode.AttachObject( particleSystem ); particleSystem.FastForward( 20 ); // Fastforward rain to make it look natural // It can't be set in .particle file, and we need it ;) //particleSystem.Origin = BillboardOrigin.BottomCenter; // Set Lighting lightNode = scene.RootSceneNode.CreateChildSceneNode(); lightSet = scene.CreateBillboardSet( "Lights", 20 ); lightSet.MaterialName = "Particles/Flare"; lightNode.AttachObject( lightSet ); SetLighting( "Ambient" ); // Add Lights - added by Najak to show lighted Water conditions - cool! #region STUBBED LIGHT ANIMATION // Create a new animation state to track this // TODO: Light Animation not working. //this.animState = scene.CreateAnimationState("WaterLight"); //this.animState.Time = 0f; //this.animState.IsEnabled = false; // set up spline animation of light node. Create random Spline Animation anim = scene.CreateAnimation( "WaterLight", 20 ); AnimationTrack track = anim.CreateNodeTrack( 0, this.lightNode ); TransformKeyFrame key = (TransformKeyFrame)track.CreateKeyFrame( 0 ); for ( int ff = 1; ff <= 19; ff++ ) { key = (TransformKeyFrame)track.CreateKeyFrame( ff ); Random rand = new Random( 0 ); Vector3 lpos = new Vector3( (float)rand.NextDouble() % (int)PLANE_SIZE, //- PLANE_SIZE/2, (float)rand.NextDouble() % 300 + 100, (float)rand.NextDouble() % (int)PLANE_SIZE ); //- PLANE_SIZE/2 key.Translate = lpos; } key = (TransformKeyFrame)track.CreateKeyFrame( 20 ); #endregion STUBBED LIGHT ANIMATION // Initialize the Materials/Demo UpdateMaterial(); UpdateInfoParamC(); UpdateInfoParamD(); UpdateInfoParamU(); UpdateInfoParamT(); UpdateInfoNormals(); UpdateInfoHeadDepth(); UpdateInfoSkyBox(); UpdateInfoHeadSpeed(); UpdateInfoLights(); UpdateInfoTracking(); // Init Head Animation: Load adds[] elements - Ogre head animation adds[ 0 ] = 0.3f; adds[ 1 ] = -1.6f; adds[ 2 ] = 1.1f; adds[ 3 ] = 0.5f; sines[ 0 ] = 0; sines[ 1 ] = 100; sines[ 2 ] = 200; sines[ 3 ] = 300; } // end CreateScene()
public virtual void NotifyAttached(Node parent) { this.parentNode = parent; if ( parent != null ) { tileSceneNode = (SceneNode)( parent.CreateChild( name ) ); //mTileNode.setPosition( (Real)mTableX , 0.0, (Real)mTableZ ); if ( renderable != null) if (renderable.IsLoaded) { tileSceneNode.AttachObject( (MovableObject) renderable ); } tileSceneNode.NeedUpdate(); } }
public override void CreateCamera() { // Create the camera camera = scene.CreateCamera( "PlayerCam" ); // NEW: create a node for the camera and control that instead of camera directly. // We do this because PCZSceneManager requires camera to have a node mCameraNode = scene.RootSceneNode.CreateChildSceneNode( "PlayerCamNode" ); // attach the camera to the node mCameraNode.AttachObject( camera ); // fix the yaw axis of the camera mCameraNode.SetFixedYawAxis( true ); camera.Near = 2; camera.Far = 1000; }
/// <summary> /// /// </summary> /// <param name="camera"></param> private void SetupCamera( Camera cam ) { // create a pivot at roughly the character's shoulder cameraPivot = cam.SceneManager.RootSceneNode.CreateChildSceneNode(); // this is where the camera should be soon, and it spins around the pivot cameraGoal = cameraPivot.CreateChildSceneNode( new Vector3( 0, 0, 15 ) ); // this is where the camera actually is cameraNode = cam.SceneManager.RootSceneNode.CreateChildSceneNode(); cameraNode.Position = cameraPivot.Position + cameraGoal.Position; cameraPivot.SetFixedYawAxis( true ); cameraGoal.SetFixedYawAxis( true ); cameraNode.SetFixedYawAxis( true ); // our model is quite small, so reduce the clipping planes cam.Near = 0.1f; cam.Far = 100; cameraNode.AttachObject( cam ); pivotPitch = 0; }
/// <summary> /// Initialize the world manager /// </summary> public void Initialize(SceneManager sceneManager, ITerrainGenerator gen, ILODSpec clientLodSpec, SceneNode root) { Debug.Assert(!initialized, "Attempt to initialize already initialized TerrainManager"); scene = sceneManager; terrainGenerator = gen; terrainGenerator.TerrainChanged += TerrainGenerator_OnTerrainChanged; lodSpec = clientLodSpec ?? defaultLODSpec; pageSize = lodSpec.PageSize; visPageRadius = lodSpec.VisiblePageRadius; pageArraySize = (visPageRadius * 2) + 1; // Compute the size of a "subPage", which is the same as the smalles tile size. // We assume that the page containing the camera will have the smallest sized tiles. subPageSize = pageSize / TilesPerPage(0); minMetersPerSample = lodSpec.MetersPerSample(Vector3.Zero, 0, 0); maxMetersPerSample = lodSpec.MetersPerSample(Vector3.Zero, visPageRadius, visPageRadius * pageSize / subPageSize); rootSceneNode = root; worldRootSceneNode = rootSceneNode.CreateChildSceneNode("TerrainRoot"); oceanSceneNode = rootSceneNode.CreateChildSceneNode("OceanNode"); terrainMaterialConfig = new AutoSplatConfig(); terrainDecalManager = new TerrainDecalManager(pageArraySize); shadowConfig = new ShadowConfig(scene); oceanConfig = new OceanConfig(); oceanConfig.ConfigChange += OceanConfigChanged; ocean = new OceanPage(oceanConfig); oceanSceneNode.AttachObject(ocean); //ocean.ShowBoundingBox = true; showOcean = true; detailVeg = new DetailVeg(65, rootSceneNode); // allocate the page array pages = new Page[pageArraySize, pageArraySize]; InitPages(); heightFieldsCreated = false; boundaries = new List<Boundary>(); roads = new Roads(); SpeedTreeWrapper.SetDropToBillboard(true); // make sure variables based on camera location are up to date CameraLocation = cameraLocation; // set up material used by water boundaries waterMaterial = MaterialManager.Instance.GetByName("MVSMWater"); if (waterMaterial != null) waterMaterial.Load(); initialized = true; }
public override void CreateScene() { // set ambient light scene.AmbientLight = new ColorEx( 0.2f, 0.2f, 0.2f ); scene.SetSkyBox( true, "Skybox/Morning", 5000 ); // create a default point light Light light = scene.CreateLight( "MainLight" ); light.Type = LightType.Directional; Vector3 dir = new Vector3( 0.5f, -1, 0 ); dir.Normalize(); light.Direction = dir; light.Diffuse = new ColorEx( 1.0f, 1.0f, 0.8f ); light.Specular = ColorEx.White; // create a plane plane = new MovablePlane( "ReflectPlane" ); plane.D = 0; plane.Normal = Vector3.UnitY; // create another plane to create the mesh. Ogre's MovablePlane uses multiple inheritance, bah! Plane tmpPlane = new Plane(); tmpPlane.D = 0; tmpPlane.Normal = Vector3.UnitY; MeshManager.Instance.CreatePlane( "ReflectionPlane", ResourceGroupManager.DefaultResourceGroupName, tmpPlane, 2000, 2000, 1, 1, true, 1, 1, 1, Vector3.UnitZ ); planeEntity = scene.CreateEntity( "Plane", "ReflectionPlane" ); // create an entity from a model Entity knot = scene.CreateEntity( "Knot", "knot.mesh" ); knot.MaterialName = "TextureFX/Knot"; // create an entity from a model Entity head = scene.CreateEntity( "Head", "ogrehead.mesh" ); // attach the render to texture entity to the root of the scene SceneNode rootNode = scene.RootSceneNode; planeNode = rootNode.CreateChildSceneNode(); planeNode.AttachObject( planeEntity ); planeNode.AttachObject( plane ); planeNode.Translate( new Vector3( 0, -10, 0 ) ); // tilt it a little to make it interesting planeNode.Roll( 5 ); rootNode.CreateChildSceneNode( "Head" ).AttachObject( head ); // create a render texture Texture texture = TextureManager.Instance.CreateManual( "RttTex", ResourceGroupManager.DefaultResourceGroupName, TextureType.TwoD, 512, 512, 0, Axiom.Media.PixelFormat.R8G8B8, TextureUsage.RenderTarget ); RenderTarget rttTex = texture.GetBuffer().GetRenderTarget(); reflectCam = scene.CreateCamera( "ReflectCam" ); reflectCam.Near = camera.Near; reflectCam.Far = camera.Far; reflectCam.AspectRatio = (float)window.GetViewport( 0 ).ActualWidth / (float)window.GetViewport( 0 ).ActualHeight; Viewport viewport = rttTex.AddViewport( reflectCam ); viewport.SetClearEveryFrame( true ); viewport.ShowOverlays = false; viewport.BackgroundColor = ColorEx.Black; Material mat = (Material)MaterialManager.Instance.Create( "RttMat", ResourceGroupManager.DefaultResourceGroupName ); TextureUnitState t = mat.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( "RustedMetal.jpg" ); t = mat.GetTechnique( 0 ).GetPass( 0 ).CreateTextureUnitState( "RttTex" ); // blend with base texture t.SetColorOperationEx( LayerBlendOperationEx.BlendManual, LayerBlendSource.Texture, LayerBlendSource.Current, ColorEx.White, ColorEx.White, 0.25f ); t.SetProjectiveTexturing( true, reflectCam ); // register events for viewport before/after update rttTex.AfterUpdate += new RenderTargetEventHandler( rttTex_AfterUpdate ); rttTex.BeforeUpdate += new RenderTargetEventHandler( rttTex_BeforeUpdate ); // set up linked reflection reflectCam.EnableReflection( plane ); // also clip reflectCam.EnableCustomNearClipPlane( plane ); planeEntity.MaterialName = "RttMat"; Entity clone = null; for ( int i = 0; i < 10; i++ ) { // create a new node under the root SceneNode node = scene.CreateSceneNode(); // calculate a random position Vector3 nodePosition = new Vector3(); nodePosition.x = Utility.SymmetricRandom() * 750.0f; nodePosition.y = Utility.SymmetricRandom() * 100.0f + 25; nodePosition.z = Utility.SymmetricRandom() * 750.0f; // set the new position node.Position = nodePosition; // attach this node to the root node rootNode.AddChild( node ); // clone the knot string cloneName = string.Format( "Knot{0}", i ); clone = knot.Clone( cloneName ); // add the cloned knot to the scene node.AttachObject( clone ); } camera.Position = new Vector3( -50, 100, 500 ); camera.LookAt( new Vector3( 0, 0, 0 ) ); }
public override void UpdateDebugDisplay( Page p, SceneNode sn ) { byte dbglvl = mManager.DebugDisplayLevel; if ( dbglvl != 0 ) { // we could try to avoid updating the geometry every time here, but this // wouldn't easily deal with paging parameter changes. There shouldn't // be that many pages anyway, and this is debug after all, so update every time int x, y; var stratData = (Grid2DPageStrategyData)p.ParentSection.StrategyData; stratData.CalculateCell( p.PageID, out x, out y ); var data = (Grid2DPageStrategyData)p.ParentSection.StrategyData; // Determine our centre point, we'll anchor here // Note that world points are initialised to ZERO since only 2 dimensions // are updated by the grid data (we could display this grid anywhere) Vector2 gridMidPoint = Vector2.Zero; Vector3 worldMidPoint = Vector3.Zero; data.GetMidPointGridSpace( x, y, ref gridMidPoint ); data.ConvertGridToWorldSpace( gridMidPoint, ref worldMidPoint ); sn.Position = worldMidPoint; var gridCorners = new Vector2[4]; var worldCorners = new Vector3[4]; data.GetCornersGridSpace( x, y, ref gridCorners ); for ( int i = 0; i < 4; ++i ) { worldCorners[ i ] = Vector3.Zero; data.ConvertGridToWorldSpace( gridCorners[ i ], ref worldCorners[ i ] ); // make relative to mid point worldCorners[ i ] -= worldMidPoint; } string matName = "Axiom/G2D/Debug"; var mat = (Material)MaterialManager.Instance.GetByName( matName ); if ( mat == null ) { mat = (Material)MaterialManager.Instance.Create( matName, ResourceGroupManager.DefaultResourceGroupName ); Pass pass = mat.GetTechnique( 0 ).GetPass( 0 ); pass.LightingEnabled = false; pass.VertexColorTracking = TrackVertexColor.Ambient; pass.DepthWrite = false; mat.Load(); } ManualObject mo = null; if ( sn.ChildCount == 0 ) { mo = p.ParentSection.SceneManager.CreateManualObject(); mo.Begin( matName, OperationType.LineStrip ); } else { mo = (ManualObject)sn.GetObject( 0 ); mo.BeginUpdate( 0 ); } ColorEx vcol = ColorEx.Green; for ( int i = 0; i < 5; ++i ) { mo.Position( worldCorners[ i%4 ] ); mo.Color( vcol ); } mo.End(); if ( sn.ObjectCount == 0 ) { sn.AttachObject( mo ); } } }