Skip to content

Commit

Permalink
Merge pull request #650 from Wolf480pl/master
Browse files Browse the repository at this point in the history
Use float versions of new template-based SpoutMath classes.
  • Loading branch information
DDoS committed Nov 7, 2013
2 parents db309e7 + 1d6757e commit 2dca85d
Show file tree
Hide file tree
Showing 160 changed files with 567 additions and 568 deletions.
6 changes: 3 additions & 3 deletions src/main/java/org/spout/vanilla/VanillaPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
import org.spout.api.plugin.services.ServiceManager;
import org.spout.api.util.FlatIterator;

import org.spout.math.imaginary.Quaternion;
import org.spout.math.vector.Vector3;
import org.spout.math.imaginary.Quaternionf;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.command.AdministrationCommands;
import org.spout.vanilla.command.AdministrationCommands.TPSMonitor;
import org.spout.vanilla.command.InputCommands;
Expand Down Expand Up @@ -262,7 +262,7 @@ private void setupWorlds() {
// Grab safe spawn if newly created world and generator is vanilla generator, else get old one.
if (newWorld && generator instanceof VanillaGenerator) {
spawn = ((VanillaGenerator) generator).getSafeSpawn(world);
world.setSpawnPoint(new Transform(spawn, Quaternion.IDENTITY, Vector3.ONE));
world.setSpawnPoint(new Transform(spawn, Quaternionf.IDENTITY, Vector3f.ONE));
} else {
spawn = world.getSpawnPoint().getPosition();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
import org.spout.api.material.BlockMaterial;
import org.spout.api.material.Material;

import org.spout.math.vector.Vector3;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.material.VanillaMaterials;
import org.spout.vanilla.material.block.plant.TallGrass;

Expand All @@ -62,7 +62,7 @@ private boolean contains(Material[] search, Material... find) {

@Override
public float getCost(BlockSource source, PathPoint point) {
Vector3 pos = point.getVector();
Vector3f pos = point.getVector();
Material above = source.getMaterialAt(pos.add(UP));
Material below = source.getMaterialAt(pos.add(DOWN));
Material in = source.getMaterialAt(pos);
Expand All @@ -84,7 +84,7 @@ private boolean isLiquid(Material... materials) {

@Override
public boolean isPassable(BlockSource source, PathPoint point) {
Vector3 pos = point.getVector();
Vector3f pos = point.getVector();
Material above = source.getMaterialAt(pos.add(UP));
Material below = source.getMaterialAt(pos.add(DOWN));
Material in = source.getMaterialAt(pos);
Expand All @@ -94,7 +94,7 @@ public boolean isPassable(BlockSource source, PathPoint point) {
return !(!canStandIn(above) || !canStandIn(in));
}

private static final Vector3 DOWN = new Vector3(0, -1, 0);
private static final Vector3f DOWN = new Vector3f(0, -1, 0);
private static final Set<Material> PASSABLE = Sets.newHashSet(VanillaMaterials.AIR, VanillaMaterials.DEAD_BUSH, VanillaMaterials.RAIL_DETECTOR, VanillaMaterials.REDSTONE_REPEATER,
VanillaMaterials.REDSTONE_REPEATER_OFF, VanillaMaterials.REDSTONE_REPEATER_ON, VanillaMaterials.FENCE_GATE, VanillaMaterials.ITEM_FRAME, VanillaMaterials.LADDER, VanillaMaterials.LEVER,
TallGrass.TALL_GRASS, VanillaMaterials.MELON_STEM, VanillaMaterials.NETHER_BRICK_FENCE, VanillaMaterials.PUMPKIN_STEM, VanillaMaterials.RAIL_POWERED, VanillaMaterials.RAIL,
Expand All @@ -103,5 +103,5 @@ public boolean isPassable(BlockSource source, PathPoint point) {
VanillaMaterials.SUGAR_CANE_BLOCK, VanillaMaterials.TRIPWIRE, VanillaMaterials.VINES, VanillaMaterials.WALL_SIGN, VanillaMaterials.WHEAT, VanillaMaterials.WATER, VanillaMaterials.WEB,
VanillaMaterials.WOOD_BUTTON, VanillaMaterials.WOODEN_DOOR, VanillaMaterials.STATIONARY_WATER);
private static final Set<Material> UNWALKABLE = Sets.union(Sets.newHashSet(VanillaMaterials.AIR, VanillaMaterials.LAVA, VanillaMaterials.STATIONARY_LAVA, VanillaMaterials.CACTUS), PASSABLE);
private static final Vector3 UP = new Vector3(0, 1, 0);
private static final Vector3f UP = new Vector3f(0, 1, 0);
}
18 changes: 9 additions & 9 deletions src/main/java/org/spout/vanilla/command/TestCommands.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
import org.spout.api.protocol.event.EntityUpdateEvent;
import org.spout.api.util.BlockIterator;

import org.spout.math.imaginary.Quaternion;
import org.spout.math.vector.Vector3;
import org.spout.math.imaginary.Quaternionf;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.ChatStyle;
import org.spout.vanilla.VanillaPlugin;
import org.spout.vanilla.component.block.material.chest.Chest;
Expand Down Expand Up @@ -247,7 +247,7 @@ public void growTree(Player player, CommandArguments args) throws CommandExcepti

BigTreeObject tree = new BigTreeObject();
tree.placeObject(pos.getWorld(), pos.getBlockX(), pos.getBlockY(), pos.getBlockZ());
player.getPhysics().setPosition(pos.add(new Vector3(0, 50, 0)));
player.getPhysics().setPosition(pos.add(new Vector3f(0, 50, 0)));
}

// TODO - There needs to be a method that guarantees unique data values on a per-server basis
Expand Down Expand Up @@ -339,7 +339,7 @@ public void respawn(Player player, CommandArguments args) throws CommandExceptio
@CommandDescription (aliases = "sun", usage = "<x> <y> <z>", desc = "Sets the sun direction.")
@Permissible ("vanilla.command.debug")
public void setSunDirection(CommandSource source, CommandArguments args) throws CommandException {
Vector3 dir = args.popVector3("dir", null);
Vector3f dir = args.popVector3("dir", null);
args.assertCompletelyParsed();
LightRenderEffect.setSun(dir);
SkyRenderEffect.setSun(dir);
Expand Down Expand Up @@ -388,7 +388,7 @@ public void traceray(CommandSource source, CommandArguments args) throws Command
@Filter (PlayerFilter.class)
public void resetPosition(Player player, CommandArguments args) throws CommandException {
args.assertCompletelyParsed();
player.getNetwork().callProtocolEvent(new EntityUpdateEvent(player, new Transform(player.getPhysics().getPosition(), player.getPhysics().getRotation(), Vector3.ONE), EntityUpdateEvent.UpdateAction.TRANSFORM, player.getNetwork().getRepositionManager()), player);
player.getNetwork().callProtocolEvent(new EntityUpdateEvent(player, new Transform(player.getPhysics().getPosition(), player.getPhysics().getRotation(), Vector3f.ONE), EntityUpdateEvent.UpdateAction.TRANSFORM, player.getNetwork().getRepositionManager()), player);
}

@CommandDescription (aliases = "torch", desc = "Place a torch.")
Expand Down Expand Up @@ -548,14 +548,14 @@ public void debug(CommandSource source, CommandArguments args) throws CommandExc
args.assertCompletelyParsed();

if (action.contains("look")) {
Quaternion rotation = player.getData().get(VanillaData.HEAD_ROTATION);
Quaternionf rotation = player.getData().get(VanillaData.HEAD_ROTATION);
Point startPosition = player.getPhysics().getPosition();
Vector3 offset = rotation.getDirection().mul(0.1);
Vector3f offset = rotation.getDirection().mul(0.1);
for (int i = 0; i < 100; i++) {
startPosition = startPosition.add(offset);
GeneralEffects.NOTE_PARTICLE.playGlobal(startPosition);
}
final Vector3 axesAngles = rotation.getAxesAngleDeg();
final Vector3f axesAngles = rotation.getAxesAngleDeg();
player.sendMessage("Yaw = " + axesAngles.getY());
player.sendMessage("Pitch = " + axesAngles.getX());
} else if (action.contains("packets")) {
Expand Down Expand Up @@ -592,7 +592,7 @@ public void data(CommandSource source, CommandArguments args) throws CommandExce
double lastDistanceToEntity = 5.0;
Point point = player.getPhysics().getPosition();
Human human = player.get(Human.class);
Vector3 direction;
Vector3f direction;
if (human == null) {
direction = player.getPhysics().getRotation().getDirection();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.spout.api.inventory.Slot;
import org.spout.api.material.Material;

import org.spout.math.vector.Vector3;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.component.block.VanillaBlockComponent;
import org.spout.vanilla.component.entity.substance.Item;
import org.spout.vanilla.data.Music;
Expand Down Expand Up @@ -83,7 +83,7 @@ public void setPlayedItem(ItemStack item) {
ItemStack old = getData().put(VanillaData.JUKEBOX_ITEM, item);
if (old != null) {
// Drop the old item
Item.drop(getPoint(), old, Vector3.UP.mul(0.5));
Item.drop(getPoint(), old, Vector3f.UP.mul(0.5));
}
setPlaying(item != null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@
import org.spout.api.inventory.Slot;

import org.spout.math.GenericMath;
import org.spout.math.vector.Vector2;
import org.spout.math.vector.Vector3;
import org.spout.math.vector.Vector2f;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.component.entity.inventory.PlayerInventory;
import org.spout.vanilla.component.entity.misc.Digging;
import org.spout.vanilla.component.entity.misc.EntityHead;
Expand Down Expand Up @@ -78,7 +78,7 @@ public void onAttached() {
TextModelComponent textModel = getOwner().get(TextModelComponent.class);
if (textModel != null) {
textModel.setSize(0.5f);
textModel.setTranslation(new Vector3(0, 3f, 0));
textModel.setTranslation(new Vector3f(0, 3f, 0));
}
//holder.getPhysics().activate(1, new BoxShape(1f, 2.3f, 1f), false, true);

Expand Down Expand Up @@ -201,13 +201,13 @@ public void dropItem(ItemStack item) {
final float maxYForce = 0.1f;

// Create a velocity vector using the transform, apply (random) force
Vector3 impulse = dropFrom.getRotation().getDirection().mul(impulseForce);
Vector3f impulse = dropFrom.getRotation().getDirection().mul(impulseForce);

// Random rotational offset to avoid dropping at the same position
Random rand = GenericMath.getRandom();
float xzLength = maxXZForce * rand.nextFloat();
float yLength = maxYForce * (rand.nextFloat() - rand.nextFloat());
impulse = impulse.add(Vector2.createRandomDirection(rand).mul(xzLength).toVector3(yLength));
impulse = impulse.add(Vector2f.createRandomDirection(rand).mul(xzLength).toVector3(yLength));

// Slightly dropping upwards
impulse = impulse.add(0.0, 0.1, 0.0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import org.spout.api.inventory.ItemStack;

import org.spout.math.GenericMath;
import org.spout.math.vector.Vector3;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.ai.action.FollowMaterialHolderAction;
import org.spout.vanilla.ai.goal.FollowMaterialHolderGoal;
import org.spout.vanilla.ai.sensor.NearbyMaterialHolderSensor;
Expand Down Expand Up @@ -84,7 +84,7 @@ public void onTick(float dt) {

private void layEgg() {
Point position = getOwner().getPhysics().getPosition();
Item.drop(position, new ItemStack(VanillaMaterials.EGG, 1), Vector3.ZERO);
Item.drop(position, new ItemStack(VanillaMaterials.EGG, 1), Vector3f.ZERO);
Float nextEgg = (float) (GenericMath.getRandom().nextInt(MINIMUM_EGG_BREEDING_TIME) + MINIMUM_EGG_BREEDING_TIME);
getOwner().getData().put(VanillaData.TIME_TILL_EGG, nextEgg);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,16 @@
import org.spout.api.geo.discrete.Transform;
import org.spout.api.util.BlockIterator;

import org.spout.math.imaginary.Quaternion;
import org.spout.math.vector.Vector3;
import org.spout.math.imaginary.Quaternionf;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.component.entity.VanillaEntityComponent;
import org.spout.vanilla.data.VanillaData;

/**
* Component that controls the rotation of a head on Vanilla resources.entities.
*/
public class EntityHead extends VanillaEntityComponent {
private Quaternion lastRotation = Quaternion.IDENTITY;
private Quaternionf lastRotation = Quaternionf.IDENTITY;

@Override
public void onAttached() {
Expand All @@ -58,18 +58,18 @@ public boolean isDirty() {
/**
* Sets the rotation of the head to look into a certain direction
*
* @param lookingAt {@link org.spout.math.vector.Vector3} to look at
* @param lookingAt {@link org.spout.math.vector.Vector3f} to look at
*/
public void setLooking(Vector3 lookingAt) {
setOrientation(Quaternion.fromRotationTo(Vector3.FORWARD, lookingAt));
public void setLooking(Vector3f lookingAt) {
setOrientation(Quaternionf.fromRotationTo(Vector3f.FORWARD, lookingAt));
}

/**
* Gets the {@link Vector3} the head is currently looking at.
* Gets the {@link org.spout.math.vector.Vector3f} the head is currently looking at.
*
* @return Head direction vector
*/
public Vector3 getLookingAt() {
public Vector3f getLookingAt() {
return getOrientation().getDirection();
}

Expand All @@ -78,7 +78,7 @@ public Vector3 getLookingAt() {
*
* @param rotation to set to
*/
public void setOrientation(Quaternion rotation) {
public void setOrientation(Quaternionf rotation) {
lastRotation = getOrientation();
getData().put(VanillaData.HEAD_ROTATION, rotation);
}
Expand All @@ -88,7 +88,7 @@ public void setOrientation(Quaternion rotation) {
*
* @return Head rotation
*/
public Quaternion getOrientation() {
public Quaternionf getOrientation() {
return getData().get(VanillaData.HEAD_ROTATION);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
import org.spout.api.entity.Entity;
import org.spout.api.inventory.ItemStack;

import org.spout.math.vector.Vector3;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.component.entity.VanillaEntityComponent;
import org.spout.vanilla.component.entity.inventory.EntityInventory;
import org.spout.vanilla.component.entity.substance.Item;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void onTick(float dt) {
if (slot == null || (slot.getMaterial() instanceof Armor && ((Armor) slot.getMaterial()).getBaseProtection() < armor.getBaseProtection())) {
getOwner().getNetwork().callProtocolEvent(new EntityCollectItemEvent(getOwner(), entity));
if (slot != null) {
Item.drop(getOwner().getPhysics().getPosition(), slot, Vector3.ZERO);
Item.drop(getOwner().getPhysics().getPosition(), slot, Vector3f.ZERO);
}
armorInv.set(i, item.getItemStack(), true);
entity.remove();
Expand All @@ -115,7 +115,7 @@ public void onTick(float dt) {
if (equip) {
getOwner().getNetwork().callProtocolEvent(new EntityCollectItemEvent(getOwner(), entity));
if (inv.getHeldItem() != null) {
Item.drop(getOwner().getPhysics().getPosition(), inv.getHeldItem(), Vector3.ZERO);
Item.drop(getOwner().getPhysics().getPosition(), inv.getHeldItem(), Vector3f.ZERO);
}
inv.getQuickbar().set(EntityQuickbarInventory.HELD_SLOT, item.getItemStack(), true);
entity.remove();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
import org.spout.api.util.Parameter;

import org.spout.math.GenericMath;
import org.spout.math.vector.Vector3;
import org.spout.math.vector.Vector3f;
import org.spout.vanilla.component.entity.VanillaEntityComponent;
import org.spout.vanilla.component.entity.inventory.EntityInventory;
import org.spout.vanilla.component.entity.living.hostile.EnderDragon;
Expand Down Expand Up @@ -273,7 +273,7 @@ private void dropDropInventory(Entity owner) {
org.spout.api.geo.discrete.Point entityPosition = owner.getPhysics().getPosition();
for (ItemStack stack : drops) {
if (stack != null) {
Item.drop(entityPosition, stack, Vector3.ZERO);
Item.drop(entityPosition, stack, Vector3f.ZERO);
}
}
if (dropComponent.getXpDrop() > 0 && VanillaConfiguration.PLAYER_SURVIVAL_ENABLE_XP.getBoolean()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,44 @@
import org.spout.api.render.Camera;
import org.spout.api.render.ViewFrustum;

import org.spout.math.matrix.Matrix4;
import org.spout.math.vector.Vector4;
import org.spout.math.matrix.Matrix4f;
import org.spout.math.vector.Vector4f;
import org.spout.vanilla.component.entity.misc.EntityHead;

public class PlayerHead extends EntityHead implements Camera {
private Matrix4 projection;
private Matrix4 view;
private Matrix4f projection;
private Matrix4f view;
private ViewFrustum frustum = new ViewFrustum();
private float fieldOfView = 75f;

public void setScale(float scale) { //1/2
projection = Matrix4.createPerspective(fieldOfView * scale, 4.0f / 3.0f, .001f * scale, 1000f * scale);
projection = Matrix4f.createPerspective(fieldOfView * scale, 4.0f / 3.0f, .001f * scale, 1000f * scale);
updateView();
}

@Override
public void onAttached() {
// TODO Get FOV
projection = Matrix4.createPerspective(fieldOfView, 4.0f / 3.0f, .001f, 1000f);
projection = Matrix4f.createPerspective(fieldOfView, 4.0f / 3.0f, .001f, 1000f);
updateView();
}

@Override
public Matrix4 getProjection() {
public Matrix4f getProjection() {
return projection;
}

@Override
public Matrix4 getView() {
public Matrix4f getView() {
return view;
}

@Override
public void updateView() {
Transform transform = getOwner().getPhysics().getTransform();
Point point = transform.getPosition().add(0.0f, getHeight(), 0.0f);
Matrix4 pos = Matrix4.createTranslation(point.mul(-1));
Matrix4 rot = getRotation();
Matrix4f pos = Matrix4f.createTranslation(point.mul(-1));
Matrix4f rot = getRotation();
view = pos.mul(rot);
frustum.update(projection, view, transform.getPosition());
}
Expand All @@ -77,9 +77,9 @@ public void updateView() {
public void updateReflectedView() {
Transform transform = getOwner().getPhysics().getTransform();
Point point = transform.getPosition().add(0.0f, getHeight(), 0.0f);
Matrix4 pos = Matrix4.createTranslation(point.mul(-1));
Matrix4 rot = getRotation();
view = Matrix4.createScaling(new Vector4(1, -1, 1, 1)).mul(pos).mul(rot);
Matrix4f pos = Matrix4f.createTranslation(point.mul(-1));
Matrix4f rot = getRotation();
view = Matrix4f.createScaling(new Vector4f(1, -1, 1, 1)).mul(pos).mul(rot);
frustum.update(projection, view, transform.getPosition());
}

Expand All @@ -94,7 +94,7 @@ public ViewFrustum getFrustum() {
}

@Override
public Matrix4 getRotation() {
return Matrix4.createRotation(getOrientation());
public Matrix4f getRotation() {
return Matrix4f.createRotation(getOrientation());
}
}
Loading

2 comments on commit 2dca85d

@ninja-
Copy link

@ninja- ninja- commented on 2dca85d Apr 29, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kinda sad that spout died...if it was re-licensed to some kind of normal license and not GPL maybe someone would pick it up and continue it.

EDIT: just noticed "but with a provision that files are released under the MIT License 180 days after they are published" - interesting :)

@lukespragg
Copy link
Member

@lukespragg lukespragg commented on 2dca85d Apr 29, 2014 via email

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.