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; }
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(); } }
/** Loads the landscape using parameters in the given in the constructor. */ public void Load( ref SceneNode RootNode ) { if ( isPreLoaded == false ) { return; } if ( isLoaded == true ) { return; } Texture.TextureManager.Instance.Load(tableX, tableZ); //create a root landscape node. pageNode = RootNode.CreateChildSceneNode( "Page." + tableX.ToString() + "." + tableZ.ToString() ); // Set node position pageNode.Position = new Vector3( (float)iniX , 0.0f, (float)iniZ ); tiles = new Tiles(); for (long i = 0; i < numTiles; i++ ) { tiles.Add( new TileRow() ); for (long j = 0; j < numTiles; j++ ) { //Debug.WriteLine(String.Format("Page[{0},{1}][{2},{3}]",tableX,tableZ,i,j)); Tile.Tile tile = TileManager.Instance.GetTile(); if ( tile != null ) { tiles[ i ].Add( tile ); tile.Init(ref pageNode,(int) tableX, (int)tableZ,(int) i, (int)j ); } else { string err = "Error: Invalid Tile: Make sure the default TileManager size is set to WorldWidth * WorldHeight * 4. Try increasing MaxNumTiles in the configuration file."; throw new ApplicationException(err); } } } for (long j = 0; j < numTiles; j++ ) { for (long i = 0; i < numTiles; i++ ) { if ( j != numTiles - 1 ) { tiles[ i ][ j ].SetNeighbor( Neighbor.South, tiles[ i ][ j + 1 ] ); tiles[ i ][ j + 1 ].SetNeighbor( Neighbor.North, tiles[ i ][ j ] ); } if ( i != numTiles - 1 ) { tiles[ i ][ j ].SetNeighbor( Neighbor.East, tiles[ i + 1 ][ j ] ); tiles[ i + 1 ][ j ].SetNeighbor( Neighbor.West, tiles[ i ][ j ] ); } } } LinkTileNeighbors(); pageNode.NeedUpdate(); isLoaded = true; }