|
31 | 31 | */ |
32 | 32 | package com.jme3.scene; |
33 | 33 |
|
| 34 | +import com.jme3.math.FastMath; |
| 35 | +import com.jme3.math.Quaternion; |
| 36 | +import com.jme3.math.Vector3f; |
34 | 37 | import com.jme3.scene.control.UpdateControl; |
35 | 38 | import org.junit.Assert; |
36 | 39 | import org.junit.Test; |
@@ -119,4 +122,33 @@ public void testAddControlAt() { |
119 | 122 | Assert.assertEquals(testSpatial, control1.getSpatial()); |
120 | 123 | Assert.assertEquals(testSpatial, control2.getSpatial()); |
121 | 124 | } |
| 125 | + |
| 126 | + @Test |
| 127 | + public void testTransferToOtherNode(){ |
| 128 | + Node nodeA = new Node("nodeA"); |
| 129 | + Node nodeB = new Node("nodeB"); |
| 130 | + Node testNode=new Node("testNode"); |
| 131 | + nodeA.setLocalTranslation(-1,0,0); |
| 132 | + nodeB.setLocalTranslation(1,0,0); |
| 133 | + nodeB.rotate(0,90* FastMath.DEG_TO_RAD,0); |
| 134 | + testNode.setLocalTranslation(1,0,0); |
| 135 | + nodeA.attachChild(testNode); |
| 136 | + Vector3f worldTranslation = testNode.getWorldTranslation().clone(); |
| 137 | + Quaternion worldRotation = testNode.getWorldRotation().clone(); |
| 138 | + |
| 139 | + Assert.assertTrue(worldTranslation.isSimilar(testNode.getWorldTranslation(),1e-6f)); |
| 140 | + Assert.assertTrue(worldRotation.isSimilar(testNode.getWorldRotation(),1e-6f)); |
| 141 | + |
| 142 | + nodeB.attachChild(testNode); |
| 143 | + |
| 144 | + Assert.assertFalse(worldTranslation.isSimilar(testNode.getWorldTranslation(),1e-6f)); |
| 145 | + Assert.assertFalse(worldRotation.isSimilar(testNode.getWorldRotation(),1e-6f)); |
| 146 | + |
| 147 | + testNode.setLocalTranslation(nodeB.worldToLocal(worldTranslation,null)); |
| 148 | + Assert.assertTrue(worldTranslation.isSimilar(testNode.getWorldTranslation(),1e-6f)); |
| 149 | + |
| 150 | + testNode.setLocalRotation(nodeB.worldToLocal(worldRotation,null)); |
| 151 | + System.out.println(testNode.getWorldRotation()); |
| 152 | + Assert.assertTrue(worldRotation.isSimilar(testNode.getWorldRotation(),1e-6f)); |
| 153 | + } |
122 | 154 | } |
0 commit comments