private void ReturnBeatBlock() //Returns playing beat block from Display above Bin to 1st Floor Rack { //Take Block from Bin and Return it to Beat Box Staging Area BeatBlockMass = RigidBody.GetMass(); CurPos = RigidBody.GetPosition(); RigidBody.SetMass(0.0f); // float floorZPosition = 0.0f; // switch (newFloor) // { // case "1": // floorZPosition = ZWarehousePos - 3.0f; // break; // case "2": // floorZPosition = ZWarehousePos - 6.0f; // break; // case "3": // floorZPosition = ZWarehousePos - 9.0f; // break; // case "4": // floorZPosition = ZWarehousePos - 12.0f; // break; // case "5": // floorZPosition = ZWarehousePos - 15.0f; // break; // case "6": // floorZPosition = ZWarehousePos - 18.0f; // break; // case "7": // floorZPosition = ZWarehousePos - 21.0f; // break; // case "8": // floorZPosition = ZWarehousePos - 24.0f; // break; // case "9": // floorZPosition = ZWarehousePos - 27.0f; // break; // default: // ScenePrivate.Chat.MessageAllUsers("Not a valid floor in Sample Warehouse"); // break; // } RigidBody.SetPosition(CurPos - OffsetPos); //Take Block from Bin and Return it to Beat Box Staging Area //CurPos = RigidBody.GetPosition(); Vector WarehousePos = new Vector(XWarehousePos, YWarehousePos, ZWarehousePos); RigidBody.SetPosition(WarehousePos); RigidBody.SetOrientation(RotQuat); RigidBody.SetMass(BeatBlockMass); hitDetected = false; }
private void DisplayBPMBlock() //Take Block from Bin and Place it Above The Bin to show what is currently playing { BeatBlockMass = RigidBody.GetMass(); CurPos = RigidBody.GetPosition(); RigidBody.SetMass(0.0f); float XDisplayPos = 1.0f; float YDisplayPos = 0.7f; float ZDisplayPos = 2.2f; Vector DisplayPos = new Vector(XDisplayPos, YDisplayPos, ZDisplayPos); RigidBody.SetPosition(DisplayPos); RigidBody.SetOrientation(RotQuat); RigidBody.SetMass(BeatBlockMass); }
private void LocalTeleport(int MoveNumber, ScriptEventData data) { Log.Write("MoveNumber: " + MoveNumber); LastCameraMan = CameraMan; foreach (AgentPrivate agent in ScenePrivate.GetAgents()) { Log.Write(agent.AgentInfo.Name); if (agent.AgentInfo.Name == CameraMan) { Log.Write("Camaeraman found"); ObjectPrivate objectPrivate = ScenePrivate.FindObject(agent.AgentInfo.ObjectId); if (objectPrivate != null) { AnimationComponent anim = null; if (objectPrivate.TryGetFirstComponent(out anim)) { RigidBody.SetPosition(MoveVector[MoveNumber]); Wait(TimeSpan.FromSeconds(0.05)); anim.SetPosition(MoveVector[MoveNumber]); Wait(TimeSpan.FromSeconds(0.05)); Quaternion rotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * RotateVector[MoveNumber]); RigidBody.SetOrientation(rotation); //PlayMovement(MoveNumber, data); } } } } }
bool ResetToInitialPosition(RigidBodyComponent rigidBody) { ObjectPrivate objectPrivate = ScenePrivate.FindObject(rigidBody.ComponentId.ObjectId); if (objectPrivate != null && objectPrivate.IsValid) { try { var motionType = rigidBody.GetMotionType(); WaitFor(rigidBody.SetMotionType, RigidBodyMotionType.MotionTypeKeyframed); rigidBody.SetAngularVelocity(Vector.Zero); rigidBody.SetLinearVelocity(Vector.Zero); rigidBody.SetOrientation(objectPrivate.InitialRotation); rigidBody.SetPosition(objectPrivate.InitialPosition); rigidBody.SetMotionType(motionType); return(true); } catch { Log.Write(LogLevel.Error, __SimpleTag, "Position Reset: error resetting object position."); } } return(false); }
void ResetToInitialPosition() { var motionType = RigidBody.GetMotionType(); WaitFor(RigidBody.SetMotionType, RigidBodyMotionType.MotionTypeKeyframed); RigidBody.SetAngularVelocity(Vector.Zero); RigidBody.SetLinearVelocity(Vector.Zero); RigidBody.SetOrientation(ObjectPrivate.InitialRotation); RigidBody.SetPosition(ObjectPrivate.InitialPosition); RigidBody.SetMotionType(motionType); }
void ResetAfterTimeout() { Wait(ResetTimeout); _rb.SetMotionType(RigidBodyMotionType.MotionTypeKeyframed); _rb.SetAngularVelocity(Vector.Zero); _rb.SetLinearVelocity(Vector.Zero); _rb.SetPosition(ObjectPrivate.InitialPosition); _rb.SetOrientation(ObjectPrivate.InitialRotation); _rb.SetMotionType(RigidBodyMotionType.MotionTypeDynamic); }
private void ReturnBeatBlock() { //Take Block from Bin and Return it to Beat Box Staging Area BeatBlockMass = RigidBody.GetMass(); CurPos = RigidBody.GetPosition(); RigidBody.SetMass(0.0f); RigidBody.SetPosition(CurPos - OffsetPos); //Take Block from Bin and Return it to Beat Box Staging Area CurPos = RigidBody.GetPosition(); Vector WarehousePos = new Vector(XWarehousePos, YWarehousePos, ZWarehousePos); RigidBody.SetPosition(WarehousePos); RigidBody.SetOrientation(RotQuat); RigidBody.SetMass(BeatBlockMass); }
private void UpdateLoop() { while (true) { //this is only one object, so we have it hard coded in to only follow the first agent., you could split this up later Boolean got1 = false; foreach (AgentPrivate agent in ScenePrivate.GetAgents()) { if (got1 == false) { ObjectPrivate agentObejct = ScenePrivate.FindObject(agent.AgentInfo.ObjectId); AnimationComponent anim; if (agentObejct.TryGetFirstComponent(out anim)) { Sansar.Vector fwd = anim.GetVectorAnimationVariable("LLCameraForward"); //Builds a rotation from the fwd vector Quaternion newRot = Quaternion.FromLook(fwd, Sansar.Vector.Up); //This is a basic check to make sure the camera rotation isnt all 0s if (fwd.LengthSquared() > 0) { try { RigidBody.SetAngularVelocity(Vector.Zero); RigidBody.SetLinearVelocity(Vector.Zero); RigidBody.SetPosition(agentObejct.Position + lightPositionOffset); //Order of multiplication matters here I think, start with the base rotation, //multiply by and base offset rotation for the light, then multiply by the rotation of the fwd //Keep in mind that multiplying quad A by quad b will rotate quad A by quad b RigidBody.SetOrientation(QuaternionToVector(startRot * lightOnObjectDirection * newRot).Normalized()); } catch { } } } got1 = true; } } Wait(TimeSpan.FromSeconds(.05)); } }
void OnDrop(HeldObjectData data) { try { unsubscribe?.Invoke(); if (ResetPositionOnDrop) { RigidBody.SetPosition(OriginalPosition); RigidBody.SetOrientation(OriginalOrientation); RigidBody.SetLinearVelocity(Sansar.Vector.Zero); RigidBody.SetAngularVelocity(Sansar.Vector.Zero); } } catch (NullReferenceException nre) { if (DebugSpam) { Log.Write("OnDrop", nre.Message); } } // ignore exceptions for not found agents. catch (Exception e) { if (DebugSpam) { Log.Write("OnDrop", e.ToString()); } } }
protected override void SimpleInit() { if (!ObjectPrivate.TryGetFirstComponent(out RigidBody)) { Log.Write(LogLevel.Error, __SimpleTag, "Simple Mover requires a Rigidbody set to motion type Keyframed"); return; } if (RigidBody.GetMotionType() != RigidBodyMotionType.MotionTypeKeyframed) { Log.Write(LogLevel.Error, __SimpleTag, "Simple Mover requires a Rigidbody set to motion type Keyframed"); return; } thisObjectData = new SimpleData(this); thisObjectData.SourceObjectId = ObjectPrivate.ObjectId; thisObjectData.AgentInfo = null; thisObjectData.ObjectId = ObjectPrivate.ObjectId; RigidBody.SetCenterOfMass(RotationPivot); Subscribe(null); Quaternion rotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * RotationOffset); returnRotation = ObjectPrivate.InitialRotation; movedRotation = returnRotation * rotation; numTurns = (int)((RotationOffset.Length() + 179.0f) / 360f); bool noRotation = RotationOffset.Length() < 0.5f; if (noRotation) { worldRotationAxis = Vector.Up; } else { float rotationAngle; rotation.ToAngleAxis(out rotationAngle, out localRotationAxis); if (Math.Abs(rotationAngle % TwoPI) < 0.001f) { // rotation axis won't be calculated correctly for exact multiple of 360 rotation // adjust euler angles slightly and re-calculate float x = RotationOffset.X; float y = RotationOffset.Y; float z = RotationOffset.Z; if (x != 0) { x = Math.Sign(x) * (Math.Abs(x) - 1.0f); } if (y != 0) { y = Math.Sign(y) * (Math.Abs(y) - 1.0f); } if (z != 0) { z = Math.Sign(z) * (Math.Abs(z) - 1.0f); } Vector adjustedOffset = new Vector(x, y, z); Quaternion adjustedRotation = Quaternion.FromEulerAngles(Mathf.RadiansPerDegree * adjustedOffset); float tempAngle; adjustedRotation.ToAngleAxis(out tempAngle, out localRotationAxis); } worldRotationAxis = localRotationAxis.Rotate(ref returnRotation); } float moveAngle = GetAngleFromZero(movedRotation); rotateSpeed = Math.Abs(moveAngle + numTurns * TwoPI) / (MoveDuration * SpeedCurveAverage()); if (!noRotation) { Quaternion unitRotation = Quaternion.FromAngleAxis(1f, localRotationAxis); turnDirection = Math.Sign(GetAngleFromZero(returnRotation * unitRotation)); } returnPosition = ObjectPrivate.InitialPosition + RotationPivot.Rotate(ref returnRotation); movedPosition = returnPosition + (PositionOffset).Rotate(ref returnRotation); translateSpeed = (movedPosition - returnPosition).Length() / (MoveDuration * SpeedCurveAverage()); if (StartMoved) { RigidBody.SetOrientation(movedRotation, (e) => { SetPositionOfCOM(movedPosition); }); turnCount = numTurns; state = State.Moved; } else { SetPositionOfCOM(returnPosition); state = State.Returned; } if (__SimpleDebugging) { Log.Write("rotation angle:" + moveAngle + " around:" + localRotationAxis + " world space axis:" + worldRotationAxis + " revolutions:" + numTurns); } }
private void GetChatCommand(ChatData Data) { string DataCmd = Data.Message; //Log.Write("DataCmd: " + DataCmd); if (SubscribeToScriptEvent("SendScreenPos", getScreenPos).Active) { Log.Write("Subscription Was Active from getChatCommmand"); } else { Log.Write("Subscription Was NOT Active from getChatCommmand"); } if ((DataCmd.Substring(0, 1) == "/") && (DataCmd.Length > 1)) { string testSlide = DataCmd.Substring(0, 2); //it was a slide command Log.Write("testSlide: " + testSlide); if ((testSlide == "/0") || (testSlide == "/1") || (testSlide == "/2") || (testSlide == "/3") || (testSlide == "/4") || (testSlide == "/5") || (testSlide == "/6") || (testSlide == "/7") || (testSlide == "/8") || (testSlide == "/9")) { int from = DataCmd.IndexOf("/", StringComparison.CurrentCulture); Log.Write("from: " + from); //Log.Write("length: " + DataCmd.Length); string test = DataCmd.Substring(from + 1, DataCmd.Length - 1); Log.Write("test: " + test); if (test == SlideNumber) { //Take Block from Bin and Return it to Beat Box Staging Area //RigidBody.SetMotionType(RigidBodyMotionType.MotionTypeDynamic); Wait(TimeSpan.FromMilliseconds(200)); //Log.Write("Slide: " + SlideNumber + " Moving to Screen"); //SlideMass = RigidBody.GetMass(); CurPos = RigidBody.GetPosition(); //Log.Write("Slide: " + SlideNumber + " CurPos: " + CurPos); //RigidBody.SetMass(0.0f); //Log.Write("Slide: " + SlideNumber + " ScreenPos: " + ScreenPos); RigidBody.SetPosition(ScreenPos); //Take Block from Bin and Return it to Beat Box Staging Area RigidBody.SetOrientation(ScreenQuat); //Log.Write("Slide: " + SlideNumber + " ScreenRot: " + ScreenQuat); Wait(TimeSpan.FromMilliseconds(200)); //RigidBody.SetMotionType(RigidBodyMotionType.MotionTypeStatic); //RigidBody.SetMass(SlideMass); } else if ((testSlide == "/0") || (testSlide == "/1") || (testSlide == "/2") || (testSlide == "/3") || (testSlide == "/4") || (testSlide == "/5") || (testSlide == "/6") || (testSlide == "/7") || (testSlide == "/8") || (testSlide == "/9")) { Log.Write("Slide: " + SlideNumber + " Moving to Storage"); //RigidBody.SetMotionType(RigidBodyMotionType.MotionTypeDynamic); Wait(TimeSpan.FromMilliseconds(200)); //CurPos = RigidBody.GetPosition(); RigidBody.SetMass(0.0f); //Take Block from Bin and Return it to Beat Box Staging Area //CurPos = RigidBody.GetPosition(); RigidBody.SetPosition(CurPos); //CurQuat = Quaternion.FromEulerAngles(CurRot).Normalized(); RigidBody.SetOrientation(CurQuat); //Wait(TimeSpan.FromMilliseconds(200)); //RigidBody.SetMotionType(RigidBodyMotionType.MotionTypeStatic); RigidBody.SetMass(SlideMass); } } } }
private void UpdateLoop() { float Tick = 0.01f; float AngleStep = 5 * OpenAngle * Tick / SecondsToOpen; TimeSpan Moment = TimeSpan.FromSeconds(Tick); float Angle = 0.0f; while (true) { Wait(Moment); // If we're in the process of opening or closing, we'll adjust the angle a little toward the target if (Opening) { if (OpenOut) { Angle -= AngleStep; if (Angle < -OpenAngle) { Angle = -OpenAngle; } } else { Angle += AngleStep; if (Angle > OpenAngle) { Angle = OpenAngle; } } // If it's been a while since we've heard an open signal, let's start closing the door if (DateTime.Now.Subtract(LatestOpenSignal).TotalSeconds >= SecondsBeforeClose) { Opening = false; if (CloseSound != null) { ScenePrivate.PlaySound(CloseSound, PlaySettings.PlayOnce); } } } else { if (OpenOut) { Angle += AngleStep; if (Angle > 0f) { Angle = 0f; } } else { Angle -= AngleStep; if (Angle < 0f) { Angle = 0f; } } } // Compute the new position and rotation of the door Quaternion Rotation = Quaternion.FromEulerAngles(new Vector(0, 0, Angle, 0)); Quaternion NewOri = ClosedOrientation * Rotation; Vector NewPos = ClosedPosition - HingeOffset.Rotate(ref Rotation); // Update the door's position and orientation DoorBody.SetAngularVelocity(Vector.Zero); DoorBody.SetLinearVelocity(Vector.Zero); DoorBody.SetPosition(NewPos); DoorBody.SetOrientation(QuaternionToVector(NewOri)); } }