public override void Update() { base.Update(); Gobject gob = GetFirstGobject(); if (gob == null) { return; } LookAtLocation(gob.BodyPosition(), Vector3.Up); }
public override void Update() { base.Update(); Gobject gob = GetFirstGobject(); if (gob == null) { return; } // bodyPosition is the physical location of the body Vector3 bodyPosition = gob.BodyPosition(); Matrix bodyOrientation = gob.BodyOrientation(); try { // the location of where it's headed Vector3 ObjectDirection = gob.BodyVelocity(); // this * 2 value is pointless I think if (ObjectDirection.Length() < 2) // this may be here just to prevent slow velocities from making a stalker camera { ObjectDirection = gob.BodyOrientation().Forward; } Vector3 WhereItsHeaded = bodyPosition + ObjectDirection; // a vector pointing toward the direction of travel //Vector3 Direction = (WhereItsHeaded - bodyPosition); ObjectDirection.Normalize(); ObjectDirection *= 10f; // this may need to be adjustable per object (planes go faster than cars) Vector3 WhereItCameFrom = bodyPosition - (ObjectDirection); Vector3 offset = new Vector3(0, 2, 0); if (profiles.ContainsKey(gob.type)) { offset = profiles[gob.type].PositionOffset; } offset = Vector3.Transform(offset, bodyOrientation); // get the correction value from the profile WhereItCameFrom += offset; TargetPosition = WhereItCameFrom; // this line caused a problem at one time. TargetLookAt = WhereItsHeaded; } catch (Exception E) { System.Diagnostics.Debug.WriteLine(E.StackTrace); } }
public override void Update() { base.Update(); Vector3 orientAdjustment = Vector3.Zero; Vector3 positionAdjustment = Vector3.Zero; Gobject gob = GetFirstGobject(); if (gob == null) { return; } int assetname = gob.type; // if this camera has a profile for this asset, if (profiles.ContainsKey(assetname)) { // get the adjustment value from the profile orientAdjustment = profiles[assetname].OrientationOffset; // get the adjustment value from the profile positionAdjustment = profiles[assetname].PositionOffset; } // create an adjustment quat for the orientation Quaternion orientOffset = Quaternion.CreateFromYawPitchRoll(orientAdjustment.Y, orientAdjustment.X, orientAdjustment.Z);// YXZ // combine body orientation and adjustment quat Quaternion newOrientation = Quaternion.CreateFromRotationMatrix(gob.BodyOrientation()) * orientOffset; // update the orientation SetTargetOrientation(newOrientation); // put the adjustment vector for the position into body coordinates positionAdjustment = Vector3.Transform(positionAdjustment, newOrientation); // update the position CurrentPosition = gob.BodyPosition() + positionAdjustment; }