Browse files

add negate

  • Loading branch information...
1 parent ef21cbc commit 29d53d5aaba8878d520ae329ca3f1ef94ad84a88 aki committed Jan 24, 2012
View
6 src/com/akjava/gwt/three/client/core/Vector3.java
@@ -79,6 +79,12 @@ public native final void setZ(double z)/*-{
}-*/;
+
+
+public native final Vector3 negate()/*-{
+return this.negate();
+}-*/;
+
public native final Vector3 addSelf(Vector3 vec3)/*-{
return this.addSelf(vec3);
}-*/;
View
46 src/com/akjava/gwt/three/client/gwt/animation/ik/CDDIK.java
@@ -5,6 +5,7 @@
import com.akjava.gwt.three.client.core.Matrix4;
import com.akjava.gwt.three.client.core.Quaternion;
import com.akjava.gwt.three.client.core.Vector3;
+import com.akjava.gwt.three.client.gwt.GWTThreeUtils;
public class CDDIK {
@@ -36,6 +37,51 @@ public Matrix4 doStep(Vector3 lastJointPos,Vector3 jointPos,Matrix4 jointRot,Ve
return matrix;
}
+
+
+public Matrix4 getStepAngleMatrix(Vector3 parentAngle,Vector3 lastJointPos,Vector3 jointPos,Matrix4 jointRot,Vector3 targetPos){
+ Vector3 parentVec=parentAngle.clone().negate();
+
+ Matrix4 mx=GWTThreeUtils.degitRotationToMatrix4(parentVec.getX(),parentVec.getY(), parentVec.getZ());
+
+ /*
+ Vector3 jointPosParent=jointPos.clone();
+ mx.multiplyVector3(jointPosParent);
+
+ Vector3 jointVector=mx.multiplyVector3(lastJointPos.clone()).subSelf(jointPosParent).normalize();
+ Vector3 targetVector=mx.multiplyVector3(targetPos.clone()).subSelf(jointPosParent).normalize();
+ */
+
+ Vector3 jointVector=lastJointPos.clone().subSelf(jointPos);
+ mx.multiplyVector3(jointVector);
+ jointVector.normalize();
+
+ Vector3 targetVector=targetPos.clone().subSelf(jointPos);
+ mx.multiplyVector3(targetVector);
+ targetVector.normalize();
+
+ double acv=jointVector.dot(targetVector);
+ double angle=Math.acos(acv);
+
+ if(angle<= 1.0e-5f){
+ return null;
+ }
+ //LogUtils.log("angle:"+angle+","+Math.toDegrees(angle));
+ Vector3 axis=THREE.Vector3().cross(jointVector,targetVector);
+ axis.normalize();
+ Quaternion q=THREE.Quaternion().setFromAxisAngle(axis,angle);
+
+
+
+
+
+
+ Matrix4 matrix=THREE.Matrix4().setRotationFromQuaternion(q);
+
+ return matrix;
+ }
+
+
public Matrix4 getStepAngleMatrix(Vector3 lastJointPos,Vector3 jointPos,Matrix4 jointRot,Vector3 targetPos){
Vector3 jointVector=lastJointPos.clone().subSelf(jointPos).normalize();

0 comments on commit 29d53d5

Please sign in to comment.