本文整理汇总了Java中com.bulletphysics.linearmath.QuaternionUtil类的典型用法代码示例。如果您正苦于以下问题:Java QuaternionUtil类的具体用法?Java QuaternionUtil怎么用?Java QuaternionUtil使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
QuaternionUtil类属于com.bulletphysics.linearmath包,在下文中一共展示了QuaternionUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: renderBoneOrientation
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
private void renderBoneOrientation(EntityRef boneEntity) {
LocationComponent loc = boneEntity.getComponent(LocationComponent.class);
if (loc == null) {
return;
}
glPushMatrix();
Vector3f worldPosA = loc.getWorldPosition();
Quat4f worldRot = loc.getWorldRotation();
Vector3f offset = new Vector3f(0, 0, 0.1f);
QuaternionUtil.quatRotate(worldRot, offset, offset);
offset.add(worldPosA);
glBegin(GL11.GL_LINES);
glVertex3f(worldPosA.x, worldPosA.y, worldPosA.z);
glVertex3f(offset.x, offset.y, offset.z);
glEnd();
for (EntityRef child : loc.getChildren()) {
renderBoneOrientation(child);
}
glPopMatrix();
}
示例2: getVertexPositions
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public List<Vector3f> getVertexPositions(List<Vector3f> bonePositions, List<Quat4f> boneRotations) {
List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount());
for (int i = 0; i < vertexStartWeights.size(); ++i) {
Vector3f vertexPos = new Vector3f();
for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) {
int weightIndex = vertexStartWeights.get(i) + weightIndexOffset;
BoneWeight weight = weights.get(weightIndex);
Vector3f current = QuaternionUtil.quatRotate(boneRotations.get(weight.getBoneIndex()), weight.getPosition(), new Vector3f());
current.add(bonePositions.get(weight.getBoneIndex()));
current.scale(weight.getBias());
vertexPos.add(current);
}
results.add(vertexPos);
}
return results;
}
示例3: getVertexNormals
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public List<Vector3f> getVertexNormals(List<Vector3f> bonePositions, List<Quat4f> boneRotations) {
List<Vector3f> results = Lists.newArrayListWithCapacity(getVertexCount());
for (int i = 0; i < vertexStartWeights.size(); ++i) {
Vector3f vertexNorm = new Vector3f();
for (int weightIndexOffset = 0; weightIndexOffset < vertexWeightCounts.get(i); ++weightIndexOffset) {
int weightIndex = vertexStartWeights.get(i) + weightIndexOffset;
BoneWeight weight = weights.get(weightIndex);
Vector3f current = QuaternionUtil.quatRotate(boneRotations.get(weight.getBoneIndex()), weight.getNormal(), new Vector3f());
current.scale(weight.getBias());
vertexNorm.add(current);
}
results.add(vertexNorm);
}
return results;
}
示例4: spawnPrefab
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
@Command(shortDescription = "Spawns an instance of a prefab in the world")
public void spawnPrefab(@CommandParam(name = "prefabId") String prefabName) {
Camera camera = CoreRegistry.get(WorldRenderer.class).getActiveCamera();
Vector3f spawnPos = camera.getPosition();
Vector3f offset = new Vector3f(camera.getViewingDirection());
offset.scale(2);
spawnPos.add(offset);
Vector3f dir = new Vector3f(camera.getViewingDirection());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(0, 0, 1);
}
Quat4f rotation = QuaternionUtil.shortestArcQuat(new Vector3f(0, 0, 1), dir, new Quat4f());
Prefab prefab = CoreRegistry.get(PrefabManager.class).getPrefab(prefabName);
if (prefab != null && prefab.getComponent(LocationComponent.class) != null) {
CoreRegistry.get(EntityManager.class).create(prefab, spawnPos, rotation);
}
}
示例5: updateWheelTransform
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public void updateWheelTransform(int wheelIndex, boolean interpolatedTransform) {
WheelInfo wheel = wheelInfo.getQuick(wheelIndex);
updateWheelTransformsWS(wheel, interpolatedTransform);
Vector3f up = Stack.alloc(Vector3f.class);
up.negate(wheel.raycastInfo.wheelDirectionWS);
Vector3f right = wheel.raycastInfo.wheelAxleWS;
Vector3f fwd = Stack.alloc(Vector3f.class);
fwd.cross(up, right);
fwd.normalize();
// up = right.cross(fwd);
// up.normalize();
// rotate around steering over de wheelAxleWS
float steering = wheel.steering;
Quat4f steeringOrn = Stack.alloc(Quat4f.class);
QuaternionUtil.setRotation(steeringOrn, up, steering); //wheel.m_steering);
Matrix3f steeringMat = Stack.alloc(Matrix3f.class);
MatrixUtil.setRotation(steeringMat, steeringOrn);
Quat4f rotatingOrn = Stack.alloc(Quat4f.class);
QuaternionUtil.setRotation(rotatingOrn, right, -wheel.rotation);
Matrix3f rotatingMat = Stack.alloc(Matrix3f.class);
MatrixUtil.setRotation(rotatingMat, rotatingOrn);
Matrix3f basis2 = Stack.alloc(Matrix3f.class);
basis2.setRow(0, right.x, fwd.x, up.x);
basis2.setRow(1, right.y, fwd.y, up.y);
basis2.setRow(2, right.z, fwd.z, up.z);
Matrix3f wheelBasis = wheel.worldTransform.basis;
wheelBasis.mul(steeringMat, rotatingMat);
wheelBasis.mul(basis2);
wheel.worldTransform.origin.scaleAdd(wheel.raycastInfo.suspensionLength, wheel.raycastInfo.wheelDirectionWS, wheel.raycastInfo.hardPointWS);
}
示例6: updateWheelTransform
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public void updateWheelTransform(int wheelIndex, boolean interpolatedTransform) {
WheelInfo wheel = wheelInfo.get(wheelIndex);
updateWheelTransformsWS(wheel, interpolatedTransform);
Vector3f up = Stack.alloc(Vector3f.class);
up.negate(wheel.raycastInfo.wheelDirectionWS);
Vector3f right = wheel.raycastInfo.wheelAxleWS;
Vector3f fwd = Stack.alloc(Vector3f.class);
fwd.cross(up, right);
fwd.normalize();
// up = right.cross(fwd);
// up.normalize();
// rotate around steering over de wheelAxleWS
float steering = wheel.steering;
Quat4f steeringOrn = Stack.alloc(Quat4f.class);
QuaternionUtil.setRotation(steeringOrn, up, steering); //wheel.m_steering);
Matrix3f steeringMat = Stack.alloc(Matrix3f.class);
MatrixUtil.setRotation(steeringMat, steeringOrn);
Quat4f rotatingOrn = Stack.alloc(Quat4f.class);
QuaternionUtil.setRotation(rotatingOrn, right, -wheel.rotation);
Matrix3f rotatingMat = Stack.alloc(Matrix3f.class);
MatrixUtil.setRotation(rotatingMat, rotatingOrn);
Matrix3f basis2 = Stack.alloc(Matrix3f.class);
basis2.setRow(0, right.x, fwd.x, up.x);
basis2.setRow(1, right.y, fwd.y, up.y);
basis2.setRow(2, right.z, fwd.z, up.z);
Matrix3f wheelBasis = wheel.worldTransform.basis;
wheelBasis.mul(steeringMat, rotatingMat);
wheelBasis.mul(basis2);
wheel.worldTransform.origin.scaleAdd(wheel.raycastInfo.suspensionLength, wheel.raycastInfo.wheelDirectionWS, wheel.raycastInfo.hardPointWS);
}
示例7: ConvexcastBatch
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public ConvexcastBatch(float ray_length, float z, float min_y, float max_y) {
boxShapeHalfExtents.set(1f, 1f, 1f);
boxShape = new BoxShape(boxShapeHalfExtents);
frame_counter = 0;
ms = 0;
max_ms = 0;
min_ms = 9999;
sum_ms_samples = 0;
sum_ms = 0;
dx = 10f;
min_x = -40;
max_x = 20;
this.min_y = min_y;
this.max_y = max_y;
sign = 1f;
float dalpha = 2f * (float)Math.PI / NUMRAYS_IN_BAR;
for (int i=0; i<NUMRAYS_IN_BAR; i++) {
float alpha = dalpha * i;
// rotate around by alpha degrees y
Quat4f q = new Quat4f(0f, 1f, 0f, alpha);
direction[i].set(1f, 0f, 0f);
Quat4f tmpQuat = new Quat4f(q);
QuaternionUtil.mul(tmpQuat, direction[i]);
direction[i].set(tmpQuat.x, tmpQuat.y, tmpQuat.z);
//direction[i].set(direction[i]);
source[i].set(min_x, max_y, z);
dest[i].scaleAdd(ray_length, direction[i], source[i]);
dest[i].y = min_y;
normal[i].set(1f, 0f, 0f);
}
}
示例8: draw
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public void draw(IGL gl) {
gl.glDisable(GL_LIGHTING);
gl.glColor3f(0f, 1f, 0f);
gl.glBegin(GL_LINES);
for (int i=0; i<NUMRAYS_IN_BAR; i++) {
gl.glVertex3f(source[i].x, source[i].y, source[i].z);
gl.glVertex3f(hit_com[i].x, hit_com[i].y, hit_com[i].z);
}
gl.glColor3f(1f, 1f, 1f);
//gl.glBegin(GL_LINES);
float normal_scale = 10f; // easier to see if this is big
for (int i=0; i<NUMRAYS_IN_BAR; i++) {
gl.glVertex3f(hit_surface[i].x, hit_surface[i].y, hit_surface[i].z);
gl.glVertex3f(hit_surface[i].x + normal_scale * normal[i].x, hit_surface[i].y + normal_scale * normal[i].y, hit_surface[i].z + normal_scale * normal[i].z);
}
gl.glEnd();
gl.glColor3f(0f, 1f, 1f);
Quat4f qFrom = Stack.alloc(Quat4f.class);
Quat4f qTo = Stack.alloc(Quat4f.class);
QuaternionUtil.setRotation(qFrom, new Vector3f(1f, 0f, 0f), 0f);
QuaternionUtil.setRotation(qTo, new Vector3f(1f, 0f, 0f), 0.7f);
for (int i=0; i<NUMRAYS_IN_BAR; i++) {
Transform from = Stack.alloc(Transform.class);
from.basis.set(qFrom);
from.origin.set(source[i]);
Transform to = Stack.alloc(Transform.class);
to.basis.set(qTo);
to.origin.set(dest[i]);
Vector3f linVel = Stack.alloc(Vector3f.class);
Vector3f angVel = Stack.alloc(Vector3f.class);
TransformUtil.calculateVelocity(from, to, 1f, linVel, angVel);
Transform T = Stack.alloc(Transform.class);
TransformUtil.integrateTransform(from, linVel, angVel, hit_fraction[i], T);
drawCube(gl, T);
}
gl.glEnable(GL_LIGHTING);
}
示例9: processAABBShape
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
private ColliderInfo processAABBShape(JsonDeserializationContext context, JsonObject colliderDef, Rotation rot) {
Vector3f offset = context.deserialize(colliderDef.get("position"), Vector3f.class);
Vector3f extent = context.deserialize(colliderDef.get("extents"), Vector3f.class);
if (offset == null) throw new JsonParseException("AABB Collider missing position");
if (extent == null) throw new JsonParseException("AABB Collider missing extents");
QuaternionUtil.quatRotate(rot.getQuat4f(), extent, extent);
extent.absolute();
return new ColliderInfo(QuaternionUtil.quatRotate(rot.getQuat4f(), offset, offset), new BoxShape(extent));
}
示例10: processSphereShape
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
private ColliderInfo processSphereShape(JsonDeserializationContext context, JsonObject colliderDef, Rotation rot) {
Vector3f offset = context.deserialize(colliderDef.get("position"), Vector3f.class);
float radius = colliderDef.get("radius").getAsFloat();
if (offset == null) throw new JsonParseException("Sphere Collider missing position");
return new ColliderInfo(QuaternionUtil.quatRotate(rot.getQuat4f(), offset, offset), new SphereShape(radius));
}
示例11: rotate
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public BlockMeshPart rotate(Quat4f rotation) {
Vector3f[] newVertices = new Vector3f[vertices.length];
Vector3f[] newNormals = new Vector3f[normals.length];
for (int i = 0; i < newVertices.length; ++i) {
newVertices[i] = QuaternionUtil.quatRotate(rotation, vertices[i], new Vector3f());
newNormals[i] = QuaternionUtil.quatRotate(rotation, normals[i], new Vector3f());
newNormals[i].normalize();
}
return new BlockMeshPart(newVertices, newNormals, texCoords, indices);
}
示例12: onMouseX
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
@ReceiveEvent(components = LocalPlayerComponent.class)
public void onMouseX(MouseXAxisEvent event, EntityRef entity) {
LocalPlayerComponent localPlayer = entity.getComponent(LocalPlayerComponent.class);
localPlayer.viewYaw = (localPlayer.viewYaw - event.getValue()) % 360;
entity.saveComponent(localPlayer);
LocationComponent loc = entity.getComponent(LocationComponent.class);
if (loc != null) {
QuaternionUtil.setEuler(loc.getLocalRotation(), TeraMath.DEG_TO_RAD * localPlayer.viewYaw, 0, 0);
entity.saveComponent(loc);
}
event.consume();
}
示例13: updateCamera
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
private void updateCamera(CharacterMovementComponent charMovementComp, Vector3f position, Quat4f rotation) {
// The camera position is the player's position plus the eye offset
Vector3d cameraPosition = new Vector3d();
// TODO: don't hardset eye position
cameraPosition.add(new Vector3d(position), new Vector3d(0, 0.6f, 0));
playerCamera.getPosition().set(cameraPosition);
Vector3f viewDir = new Vector3f(0, 0, 1);
QuaternionUtil.quatRotate(rotation, viewDir, playerCamera.getViewingDirection());
float stepDelta = charMovementComp.footstepDelta - lastStepDelta;
if (stepDelta < 0) stepDelta += charMovementComp.distanceBetweenFootsteps;
bobFactor += stepDelta;
lastStepDelta = charMovementComp.footstepDelta;
if (playerCamera.getClass() == PerspectiveCamera.class) {
if (config.getRendering().isCameraBobbing()) {
((PerspectiveCamera) playerCamera).setBobbingRotationOffsetFactor(calcBobbingOffset(0.0f, 0.01f, 2.5f));
((PerspectiveCamera) playerCamera).setBobbingVerticalOffsetFactor(calcBobbingOffset((float) java.lang.Math.PI / 4f, 0.025f, 3f));
} else {
((PerspectiveCamera) playerCamera).setBobbingRotationOffsetFactor(0.0f);
((PerspectiveCamera) playerCamera).setBobbingVerticalOffsetFactor(0.0f);
}
}
if (charMovementComp.isGhosting) {
playerCamera.extendFov(24);
} else {
playerCamera.resetFov();
}
}
示例14: getLocalPosition
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public Vector3f getLocalPosition() {
Vector3f pos = new Vector3f(objectSpacePos);
if (parent != null) {
pos.sub(parent.getObjectPosition());
Quat4f inverseParentRot = new Quat4f();
inverseParentRot.inverse(parent.getObjectRotation());
QuaternionUtil.quatRotate(inverseParentRot, pos, pos);
}
return pos;
}
示例15: getViewRotation
import com.bulletphysics.linearmath.QuaternionUtil; //导入依赖的package包/类
public Quat4f getViewRotation() {
LocalPlayerComponent character = getEntity().getComponent(LocalPlayerComponent.class);
if (character == null) {
return new Quat4f(0, 0, 0, 1);
}
Quat4f rot = new Quat4f();
QuaternionUtil.setEuler(rot, TeraMath.DEG_TO_RAD * character.viewYaw, TeraMath.DEG_TO_RAD * character.viewPitch, 0);
return rot;
}