/** Multiplies the vector by the given {@link Quaternion}. * @return This vector for chaining */ public Vector3 mul (final Quaternion quat) { return quat.transform(this); }
/** Multiplies the vector by the given {@link Quaternion}. * @return This vector for chaining */ public Vector3 mul (final Quaternion quat) { return quat.transform(this); }
/** Multiplies the vector by the given {@link Quaternion}. * @return This vector for chaining */ public Vector3 mul (final Quaternion quat) { return quat.transform(this); }
/** Multiplies the vector by the given {@link Quaternion}. * @return This vector for chaining */ public Vector3 mul (final Quaternion quat) { return quat.transform(this); }
/** * Sets the vector to point in the direction the model is facing * * @param out Output vector * @return The output vector for chaining */ public Vector3 getDirection(Vector3 out) { return modelTransform.getRotation(tmpQuat, true).transform(out.set(Vector3.Z)); }
/** * Direction vector of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneDirection(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; node.globalTransform.getTranslation(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V1.sub(TMP_V2).scl(-1); modelInstance.transform.getRotation(TMP_Q); TMP_Q.transform(TMP_V1); return out.set(TMP_V1).nor(); }
private void drawArmatureNodes(Node currentNode, Vector3 modelPos, Quaternion modelRot, Vector3 parentNodePos, Vector3 currentNodePos) { currentNode.globalTransform.getTranslation(currentNodePos); modelRot.transform(currentNodePos); currentNodePos.add(modelPos); drawVertex(currentNodePos, 0.02f, Color.GREEN); shapeRenderer.setColor(Color.YELLOW); if (currentNode.hasParent()) { shapeRenderer.line(parentNodePos, currentNodePos); } if (currentNode.hasChildren()) { float x = currentNodePos.x; float y = currentNodePos.y; float z = currentNodePos.z; for (Node child : currentNode.getChildren()) { drawArmatureNodes(child, modelPos, modelRot, currentNodePos, parentNodePos); currentNodePos.set(x, y, z); } } }
/** * Midpoint of an armature bone, in world coordinate system. * * @param nodeId Name of the bone * @param out Output vector * @return Output vector for chaining */ public Vector3 getBoneMidpointWorldPosition(String nodeId, Vector3 out) { Node node = modelInstance.getNode(nodeId); Node endPointNode = (node.hasChildren()) ? node.getChild(0) : node; // Use global transform to account for model scaling node.globalTransform.getTranslation(TMP_V1); TMP_V3.set(TMP_V1); endPointNode.globalTransform.getTranslation(TMP_V2); TMP_V3.sub(TMP_V1.sub(TMP_V2).scl(0.5f)); modelInstance.transform.getRotation(TMP_Q, true).transform(TMP_V3); TMP_V3.add(getPosition()); return out.set(TMP_V3); } }
public void throwStick() { GameScreen.screen.engine.addEntity(stick); stick.body.setLinearVelocity(Vector3.Zero); stick.body.setAngularVelocity(Vector3.Zero); Vector3 rightHandPos = getBoneMidpointWorldPosition(HumanArmature.RIGHT_HAND.id, TMP_V1); stick.modelTransform.setToRotation(Vector3.Z, 90); stick.modelTransform.rotate(Constants.V3_UP, getOrientation() * MathUtils.radiansToDegrees); stick.modelTransform.setTranslation(rightHandPos); stick.body.setWorldTransform(stick.modelTransform); Vector3 humanDirection = getDirection(TMP_V1); TMP_Q.setFromAxis(TMP_V2.set(humanDirection).crs(Constants.V3_UP), STICK_THROW_ANGLE); Vector3 impulse = TMP_Q.transform(humanDirection).nor(); impulse.scl(STICK_THROW_IMPULSE_SCL); stick.body.applyImpulse(impulse, TMP_V2.set(Constants.V3_UP).scl(0.005f)); stick.hasLanded = false; hasStick = false; }