• Breaking News

    Regarding rotation of objects away from origin (With 64-bit precision) I am having an issue with a short piece of code relating to rotation. Basically, I am trying to rotate an object (a planet, divided into chunks) about the origin (0,0,0). However, I am using a "floating origin" system which translates all objects in the world in the opposite direction to the players movement, to keep the player position at the origin (So, essentially, the world moves, not the player).The below code works fine when the player is at the origin when the rotation is performed. But when the objects being rotated are moved from the origin (to simulate the player moving in the opposite direction) and the rotation is performed after the shift, the rotation is wrong.I have tried changing the position of the centeroforbit object so that it remains fixed at 0,0,0, but this hasn't worked. I achieved some success by changing the centeroforbit position to the worldspace position of the player. This almost worked, but the rotation value wasn't quite correct. I am using the Unity game engine, but any advice would be appreciated. I know this is a long shot, and it's difficult to explain what exactly is happening here, but can anyone see any way to get the below code to work properly even when the position of the object being rotated changes, and moves from the origin?The handle rotation code is inside an update loop, and it called continuously. This is the original code, this works fine only when the rotation is performed before the objects are moved: Code (CSharp): private void HandleRotation() { PW_Vector3D rotatedPosition; PW_Quaternion3D orbitRot = new PW_Quaternion3D(tDesc.rotationobject.transform.rotation); PW_Vector3D ppos = body.GetComponent().planetposition; double orbitRadius = PW_Vector3D.Distance(ppos, tDesc.centreOfOrbit.GetComponent().position); rotatedPosition = orbitRot * (startingPosition + new PW_Vector3D(orbitRadius, 0, 0)); rotatedPosition += tDesc.centreOfOrbit.GetComponent().position; Quaternion q2 = Quaternion.Inverse(Quaternion.identity) * orbitRot.toQuaternion(); this.transform.position = rotatedPosition.toVector3f(); GetComponent().position = rotatedPosition; this.transform.rotation = q2; } This code *almost* works when the rotation occurs after shifting the objects, but the rotation is slightly off for some reason: Code (CSharp): private void HandleRotation() { PW_Vector3D rotatedPosition; PW_Quaternion3D orbitRot = new PW_Quaternion3D(tDesc.rotationobject.transform.rotation); PW_Vector3D ppos = body.GetComponent().planetposition; PW_Vector3D v1 = mcs.shipworldspacepos; double orbitRadius = PW_Vector3D.Distance(ppos,v1); rotatedPosition = orbitRot * (startingPosition + new PW_Vector3D(orbitRadius, 0, 0)); rotatedPosition += v1; Quaternion q2 = Quaternion.Inverse(Quaternion.identity) * orbitRot.toQuaternion(); this.transform.position = rotatedPosition.toVector3f(); GetComponent().position = rotatedPosition; this.transform.rotation = q2; } Thanks a lot for any advice that anyone can offer. https://ift.tt/eA8V8J

    I am having an issue with a short piece of code relating to rotation. Basically, I am trying to rotate an object (a planet, divided into chunks) about the origin (0,0,0). However, I am using a "floating origin" system which translates all objects in the world in the opposite direction to the players movement, to keep the player position at the origin (So, essentially, the world moves, not the player).The below code works fine when the player is at the origin when the rotation is performed. But when the objects being rotated are moved from the origin (to simulate the player moving in the opposite direction) and the rotation is performed after the shift, the rotation is wrong.I have tried changing the position of the centeroforbit object so that it remains fixed at 0,0,0, but this hasn't worked. I achieved some success by changing the centeroforbit position to the worldspace position of the player. This almost worked, but the rotation value wasn't quite correct. I am using the Unity game engine, but any advice would be appreciated. I know this is a long shot, and it's difficult to explain what exactly is happening here, but can anyone see any way to get the below code to work properly even when the position of the object being rotated changes, and moves from the origin?The handle rotation code is inside an update loop, and it called continuously. This is the original code, this works fine only when the rotation is performed before the objects are moved: Code (CSharp): private void HandleRotation() { PW_Vector3D rotatedPosition; PW_Quaternion3D orbitRot = new PW_Quaternion3D(tDesc.rotationobject.transform.rotation); PW_Vector3D ppos = body.GetComponent<PW_Planet>().planetposition; double orbitRadius = PW_Vector3D.Distance(ppos, tDesc.centreOfOrbit.GetComponent<PW_StaticObjectShifter>().position); rotatedPosition = orbitRot * (startingPosition + new PW_Vector3D(orbitRadius, 0, 0)); rotatedPosition += tDesc.centreOfOrbit.GetComponent<PW_StaticObjectShifter>().position; Quaternion q2 = Quaternion.Inverse(Quaternion.identity) * orbitRot.toQuaternion(); this.transform.position = rotatedPosition.toVector3f(); GetComponent<PW_StaticObjectShifter>().position = rotatedPosition; this.transform.rotation = q2; } This code *almost* works when the rotation occurs after shifting the objects, but the rotation is slightly off for some reason: Code (CSharp): private void HandleRotation() { PW_Vector3D rotatedPosition; PW_Quaternion3D orbitRot = new PW_Quaternion3D(tDesc.rotationobject.transform.rotation); PW_Vector3D ppos = body.GetComponent<PW_Planet>().planetposition; PW_Vector3D v1 = mcs.shipworldspacepos; double orbitRadius = PW_Vector3D.Distance(ppos,v1); rotatedPosition = orbitRot * (startingPosition + new PW_Vector3D(orbitRadius, 0, 0)); rotatedPosition += v1; Quaternion q2 = Quaternion.Inverse(Quaternion.identity) * orbitRot.toQuaternion(); this.transform.position = rotatedPosition.toVector3f(); GetComponent<PW_StaticObjectShifter>().position = rotatedPosition; this.transform.rotation = q2; } Thanks a lot for any advice that anyone can offer.

    from GameDev.net http://bit.ly/2UXImSO

    ليست هناك تعليقات

    Post Top Ad

    ad728

    Post Bottom Ad

    ad728