use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class CoreCommands method spawnPrefab.
/**
* Spawns an instance of a prefab in the world
*
* @param sender Sender of command
* @param prefabName String containing prefab name
* @return String containing final message
*/
@Command(shortDescription = "Spawns an instance of a prefab in the world", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String spawnPrefab(@Sender EntityRef sender, @CommandParam("prefabId") String prefabName) {
ClientComponent clientComponent = sender.getComponent(ClientComponent.class);
LocationComponent characterLocation = clientComponent.character.getComponent(LocationComponent.class);
Vector3f spawnPos = characterLocation.getWorldPosition(new Vector3f());
Vector3f offset = characterLocation.getWorldDirection(new Vector3f());
offset.mul(2);
spawnPos.add(offset);
Vector3f dir = characterLocation.getWorldDirection(new Vector3f());
dir.y = 0;
if (dir.lengthSquared() > 0.001f) {
dir.normalize();
} else {
dir.set(Direction.FORWARD.asVector3f());
}
return Assets.getPrefab(prefabName).map(prefab -> {
LocationComponent loc = prefab.getComponent(LocationComponent.class);
if (loc != null) {
entityManager.create(prefab, spawnPos);
return "Done";
} else {
return "Prefab cannot be spawned (no location component)";
}
}).orElse("Unknown prefab");
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class ClientCommands method setSpawnLocation.
/**
* Sets the spawn location for the client to the current location
* @return String containing debug information on the entity
*/
@Command(shortDescription = "Sets the spawn location for the client to the current location", runOnServer = true, requiredPermission = PermissionManager.CHEAT_PERMISSION)
public String setSpawnLocation(@Sender EntityRef sender) {
EntityRef clientInfo = sender.getComponent(ClientComponent.class).clientInfo;
StaticSpawnLocationComponent staticSpawnLocationComponent = new StaticSpawnLocationComponent();
if (clientInfo.hasComponent(StaticSpawnLocationComponent.class)) {
staticSpawnLocationComponent = clientInfo.getComponent(StaticSpawnLocationComponent.class);
}
staticSpawnLocationComponent.position = sender.getComponent(ClientComponent.class).character.getComponent(LocationComponent.class).getWorldPosition(new Vector3f());
clientInfo.addOrSaveComponent(staticSpawnLocationComponent);
return "Set spawn location to- " + staticSpawnLocationComponent.position;
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class BulletConvexHullShape method getVertices.
@Override
public Vector3f[] getVertices() {
Vector3f[] verts = new Vector3f[convexHullShape.getNumPoints()];
for (int x = 0; x < convexHullShape.getNumPoints(); x++) {
Vector3f p = new Vector3f(convexHullShape.getScaledPoint(x));
verts[x] = p;
}
return verts;
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class RigidBodyComponent method copyFrom.
@Override
public void copyFrom(RigidBodyComponent other) {
this.mass = other.mass;
this.kinematic = other.kinematic;
this.velocity = new Vector3f(other.velocity);
this.angularFactor = new Vector3f(other.angularFactor);
this.linearFactor = new Vector3f(other.linearFactor);
this.friction = other.friction;
this.restitution = other.restitution;
this.angularVelocity = new Vector3f(other.angularVelocity);
this.collisionGroup = other.collisionGroup;
this.collidesWith = Lists.newArrayList(other.collidesWith);
}
use of org.joml.Vector3f in project Terasology by MovingBlocks.
the class PhysicsSystem method update.
@Override
public void update(float delta) {
PerformanceMonitor.startActivity("Physics Renderer");
physics.update(time.getGameDelta());
PerformanceMonitor.endActivity();
// Update the velocity from physics engine bodies to Components:
Iterator<EntityRef> iter = physics.physicsEntitiesIterator();
while (iter.hasNext()) {
EntityRef entity = iter.next();
RigidBodyComponent comp = entity.getComponent(RigidBodyComponent.class);
RigidBody body = physics.getRigidBody(entity);
// force location component to update and sync trigger state
if (entity.hasComponent(TriggerComponent.class)) {
physics.updateTrigger(entity);
}
if (body.isActive()) {
body.getLinearVelocity(comp.velocity);
body.getAngularVelocity(comp.angularVelocity);
Vector3f vLocation = body.getLocation(new Vector3f());
Vector3f vDirection = new Vector3f(comp.velocity);
float fDistanceThisFrame = vDirection.length();
vDirection.normalize();
fDistanceThisFrame = fDistanceThisFrame * delta;
while (true) {
HitResult hitInfo = physics.rayTrace(vLocation, vDirection, fDistanceThisFrame + 0.5f, DEFAULT_COLLISION_GROUP);
if (hitInfo.isHit()) {
Block hitBlock = worldProvider.getBlock(hitInfo.getBlockPosition());
if (hitBlock != null) {
Vector3f vTravelledDistance = vLocation.sub(hitInfo.getHitPoint());
float fTravelledDistance = vTravelledDistance.length();
if (fTravelledDistance > fDistanceThisFrame) {
break;
}
if (hitBlock.isPenetrable()) {
if (!hitInfo.getEntity().hasComponent(BlockComponent.class)) {
entity.send(new EntityImpactEvent(hitInfo.getHitPoint(), hitInfo.getHitNormal(), comp.velocity, fDistanceThisFrame, hitInfo.getEntity()));
break;
}
// decrease the remaining distance to check if we hit a block
fDistanceThisFrame = fDistanceThisFrame - fTravelledDistance;
vLocation = hitInfo.getHitPoint();
} else {
entity.send(new BlockImpactEvent(hitInfo.getHitPoint(), hitInfo.getHitNormal(), comp.velocity, fDistanceThisFrame, hitInfo.getEntity()));
break;
}
} else {
break;
}
} else {
break;
}
}
}
}
if (networkSystem.getMode().isServer() && time.getGameTimeInMs() - TIME_BETWEEN_NETSYNCS > lastNetsync) {
sendSyncMessages();
lastNetsync = time.getGameTimeInMs();
}
List<CollisionPair> collisionPairs = physics.getCollisionPairs();
for (CollisionPair pair : collisionPairs) {
if (pair.b.exists()) {
short bCollisionGroup = getCollisionGroupFlag(pair.b);
short aCollidesWith = getCollidesWithGroupFlag(pair.a);
if ((bCollisionGroup & aCollidesWith) != 0 || (pair.b.hasComponent(BlockComponent.class) && !pair.a.hasComponent(BlockComponent.class))) {
pair.a.send(new CollideEvent(pair.b, pair.pointA, pair.pointB, pair.distance, pair.normal));
}
}
if (pair.a.exists()) {
short aCollisionGroup = getCollisionGroupFlag(pair.a);
short bCollidesWith = getCollidesWithGroupFlag(pair.b);
if ((aCollisionGroup & bCollidesWith) != 0 || (pair.a.hasComponent(BlockComponent.class) && !pair.b.hasComponent(BlockComponent.class))) {
pair.b.send(new CollideEvent(pair.a, pair.pointB, pair.pointA, pair.distance, new Vector3f(pair.normal).mul(-1.0f)));
}
}
}
}
Aggregations