/// <summary> /// Called when this block is placed in the world /// </summary> public override bool BlockPlaced(World world, Vector3 position, Vector3 blockClicked, byte facing, Entities.Entity placedBy) { // Get facing facing = MathHelper.DirectionByRotationFlat(placedBy); Vector3 secondHalf = position.Clone(); byte occupied = 0x4; switch ((Directions)facing) { case Directions.North: facing = (byte)Bed.North; secondHalf.X--; break; case Directions.East: facing = (byte)Bed.East; secondHalf.Z--; break; case Directions.West: facing = (byte)Bed.West; secondHalf.Z++; break; case Directions.South: facing = (byte)Bed.South; secondHalf.X++; break; } this.Metadata = facing; Block other = world.GetBlock(secondHalf); if (!(other is AirBlock)) return false; other = new BedBlock(); other.Metadata = (byte)(facing | 0x08); world.SetBlock(secondHalf, other); return true; }
/// <summary> /// Initializes a new instance of the <see cref="Posit"/> class. /// </summary> /// /// <param name="model">Array of vectors containing coordinates of four real model's point.</param> /// <param name="focalLength">Effective focal length of the camera used to capture the model.</param> /// /// <exception cref="ArgumentException">The model must have 4 points.</exception> /// public CoplanarPosit( Vector3[] model, float focalLength ) { if ( model.Length != 4 ) { throw new ArgumentException( "The model must have 4 points." ); } this.focalLength = focalLength; modelPoints = (Vector3[]) model.Clone( ); // compute model vectors modelVectors = Matrix3x3.CreateFromRows( model[1] - model[0], model[2] - model[0], model[3] - model[0] ); // compute pseudo inverse of the model matrix Matrix3x3 u, v; Vector3 e; modelVectors.SVD( out u, out e, out v ); modelPseudoInverse = v * Matrix3x3.CreateDiagonal( e.Inverse( ) ) * u.Transpose( ); // computer unit vector normal to the model modelNormal = v.GetColumn( e.MinIndex ); }
/// <summary> /// Initializes a new instance of the <see cref="Posit"/> class. /// </summary> /// /// <param name="model">Array of vectors containing coordinates of four real model's point (points /// must not be on the same plane).</param> /// <param name="focalLength">Effective focal length of the camera used to capture the model.</param> /// /// <exception cref="ArgumentException">The model must have 4 points.</exception> /// public Posit( Vector3[] model, float focalLength ) { if ( model.Length != 4 ) { throw new ArgumentException( "The model must have 4 points." ); } this.focalLength = focalLength; modelPoints = (Vector3[]) model.Clone( ); // compute model vectors modelVectors = Matrix3x3.CreateFromRows( model[1] - model[0], model[2] - model[0], model[3] - model[0] ); // compute pseudo inverse matrix modelPseudoInverse = modelVectors.PseudoInverse( ); }