/** * @return the portion of direction that is parallel to normal */ public static Vector3f getParallelComponent(Vector3f direction, Vector3f normal, Vector3f out) { out.set(normal); out.scale(direction.dot(normal)); return out; }
/** * @return The reflection of direction against normal */ public static Vector3f reflect(Vector3f direction, Vector3f normal, Vector3f out) { out.set(normal); out.scale(-2.0f * direction.dot(normal)); out.add(direction); return out; }
public static Side getSecondaryPlacementDirection(Vector3f direction, Vector3f normal) { Side surfaceDir = Side.inDirection(normal); Vector3f attachDir = surfaceDir.reverse().getVector3i().toVector3f(); Vector3f rawDirection = new Vector3f(direction); float dot = rawDirection.dot(attachDir); rawDirection.sub(new Vector3f(dot * attachDir.x, dot * attachDir.y, dot * attachDir.z)); return Side.inDirection(rawDirection.x, rawDirection.y, rawDirection.z).reverse(); }
float originalSlope = callback.getHitNormalWorld().dot(new Vector3f(0, 1, 0)); if (originalSlope < slopeFactor) { float slope = callback.calculateAverageSlope(originalSlope, CHECK_FORWARD_DIST); if (sqrDist > physics.getEpsilon()) { expectedMove.normalize(); if (expectedMove.dot(normalizedDir) <= 0.0f) { hit = true; break;
sunPositionScreenSpace.w = 1.0f; lightShaftsMaterial.setFloat("lightDirDotViewDir", activeCamera.getViewingDirection().dot(sunDirection), true); lightShaftsMaterial.setFloat2("lightScreenPos", (sunPositionScreenSpace.x + 1.0f) / 2.0f, (sunPositionScreenSpace.y + 1.0f) / 2.0f, true);
Vector3f newDir = new Vector3f(normalizedDir); newDir.scale(dist); float slope = callback.getHitNormalWorld().dot(new Vector3f(0, 1, 0)); if (horizNormal.lengthSquared() > physics.getEpsilon()) { horizNormal.normalize(); if (lastHitNormal.dot(horizNormal) > physics.getEpsilon()) { break; if (sqrDist > physics.getEpsilon()) { newDir.normalize(); if (newDir.dot(normalizedDir) <= 0.0f) { break;
@ReceiveEvent public void onItemImpact(ImpactEvent event, EntityRef entity) { RigidBody rigidBody = physics.getRigidBody(entity); if (rigidBody != null) { Vector3f vImpactNormal = new Vector3f(event.getImpactNormal()); Vector3f vImpactPoint = new Vector3f(event.getImpactPoint()); Vector3f vImpactSpeed = new Vector3f(event.getImpactSpeed()); float speedFactor = vImpactSpeed.length(); vImpactNormal.normalize(); vImpactSpeed.normalize(); float dotImpactNormal = vImpactSpeed.dot(vImpactNormal); Vector3f impactResult = vImpactNormal.mul(dotImpactNormal); impactResult = vImpactSpeed.sub(impactResult.mul(2.0f)); impactResult.normalize(); Vector3f vNewLocationVector = (new Vector3f(impactResult)).mul(event.getTravelDistance()); Vector3f vNewPosition = (new Vector3f(vImpactPoint)).add(vNewLocationVector); Vector3f vNewVelocity = (new Vector3f(impactResult)).mul(speedFactor * COLLISION_DAMPENING_MULTIPLIER); rigidBody.setLocation(vNewPosition); rigidBody.setLinearVelocity(vNewVelocity); rigidBody.setAngularVelocity(vNewVelocity); } }