Skip to content

Commit

Permalink
Merge branch 'new-math'
Browse files Browse the repository at this point in the history
  • Loading branch information
DDoS committed Sep 1, 2013
2 parents 3755bab + 6488296 commit e96aa1b
Show file tree
Hide file tree
Showing 182 changed files with 593 additions and 8,091 deletions.
6 changes: 6 additions & 0 deletions api/pom.xml
Expand Up @@ -96,6 +96,12 @@
<version>1.0.5-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.spout</groupId>
<artifactId>spout-math</artifactId>
<version>1.0.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/spout/api/Client.java
Expand Up @@ -31,9 +31,9 @@
import org.spout.api.geo.World;
import org.spout.api.gui.ScreenStack;
import org.spout.api.input.InputManager;
import org.spout.api.math.Vector2;
import org.spout.api.protocol.PortBinding;
import org.spout.api.render.RenderMode;
import org.spout.math.vector.Vector2;

/**
* Represents the client-specific component of the Spout platform.
Expand Down
Expand Up @@ -27,7 +27,7 @@
package org.spout.api.ai.pathfinder;

import org.spout.api.material.Material;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

public interface BlockSource {
int getBlockTypeIdAt(int x, int y, int z);
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/spout/api/ai/pathfinder/Path.java
Expand Up @@ -35,7 +35,7 @@
import org.spout.api.entity.Entity;
import org.spout.api.geo.World;
import org.spout.api.geo.cuboid.Block;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

public class Path implements Plan<Entity> {
private int index = 0;
Expand Down
Expand Up @@ -28,7 +28,7 @@

import org.spout.api.entity.Entity;
import org.spout.api.geo.cuboid.Block;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

public interface PathPoint {
void addCallback(PathCallback callback);
Expand Down
Expand Up @@ -29,7 +29,7 @@
import org.spout.api.geo.World;
import org.spout.api.geo.discrete.Point;
import org.spout.api.material.Material;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

public class SpoutBlockSource extends AbstractBlockSource {
private final World world;
Expand Down
Expand Up @@ -26,7 +26,7 @@
*/
package org.spout.api.ai.pathfinder;

import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

public class VectorGoal implements org.spout.api.ai.AStarGoal<VectorNode> {
private final Vector3 goal;
Expand Down
Expand Up @@ -31,7 +31,7 @@
import com.google.common.collect.Lists;

import org.spout.api.ai.AStarNode;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

public class VectorNode extends AStarNode implements PathPoint {
private float blockCost = -1;
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/spout/api/audio/SoundListener.java
Expand Up @@ -27,7 +27,7 @@
package org.spout.api.audio;

import org.spout.api.geo.discrete.Point;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

/**
* Listens for Sounds.
Expand Down
2 changes: 1 addition & 1 deletion api/src/main/java/org/spout/api/audio/SoundSource.java
Expand Up @@ -30,7 +30,7 @@

import org.spout.api.geo.World;
import org.spout.api.geo.discrete.Point;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;

/**
* Represents a source of sound in the game.
Expand Down
Expand Up @@ -27,8 +27,8 @@
package org.spout.api.collision;

import org.spout.api.math.ReactConverter;
import org.spout.api.math.Vector3;

import org.spout.math.vector.Vector3;
import org.spout.physics.collision.ContactInfo;

public class SpoutContactInfo {
Expand Down
Expand Up @@ -45,7 +45,7 @@
import org.spout.api.exception.CommandException;
import org.spout.api.geo.World;
import org.spout.api.geo.discrete.Point;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;
import org.spout.api.plugin.Plugin;

/**
Expand Down
Expand Up @@ -27,65 +27,63 @@
package org.spout.api.component.entity;

import org.spout.api.geo.discrete.Transform;
import org.spout.api.math.Matrix;
import org.spout.api.math.MatrixMath;
import org.spout.api.math.Vector3;
import org.spout.api.render.Camera;
import org.spout.api.render.ViewFrustum;

import org.spout.math.matrix.Matrix4;

public class CameraComponent extends EntityComponent implements Camera {
private ViewFrustum frustum;
private Matrix projection;
private Matrix view;
private Matrix4 projection;
private Matrix4 view;
private ViewFrustum frustum = new ViewFrustum();
private float fieldOfView = 75f;

public CameraComponent() {
this.frustum = new ViewFrustum();
}

public CameraComponent(Matrix createPerspective, Matrix createLookAt) {
this();
this.projection = createPerspective;
this.view = createLookAt;
public CameraComponent(Matrix4 createPerspective, Matrix4 createLookAt) {
projection = createPerspective;
view = createLookAt;
}

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

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

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

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

@Override
public void updateView() {
Transform transform = getOwner().getPhysics().getTransform().copy().translate(0, 2, 0);
Matrix pos = MatrixMath.createTranslated(transform.getPosition().multiply(-1));
Matrix rot = MatrixMath.createRotated(transform.getRotation());
view = pos.multiply(rot);
Transform transform = getOwner().getPhysics().getTransformRender();
Matrix4 pos = Matrix4.createTranslation(transform.getPosition().mul(-1));
Matrix4 rot = Matrix4.createRotation(transform.getRotation());
view = pos.mul(rot);
frustum.update(projection, view, transform.getPosition());
}

@Override
public void updateReflectedView() {
Transform transform = getOwner().getPhysics().getTransform().copy().translate(0, 2, 0);
Matrix pos = MatrixMath.createTranslated(transform.getPosition().multiply(-1, 1, -1));
Matrix rot = MatrixMath.createRotated(transform.getRotation());
view = MatrixMath.createScaled(new Vector3(1, -1, 1)).multiply(pos).multiply(rot);
Transform transform = getOwner().getPhysics().getTransformRender();
Matrix4 pos = Matrix4.createTranslation(transform.getPosition().mul(-1, 1, -1));
Matrix4 rot = Matrix4.createRotation(transform.getRotation());
view = Matrix4.createScaling(1, -1, 1, 1).mul(pos).mul(rot);
frustum.update(projection, view, transform.getPosition());
}

Expand All @@ -100,8 +98,8 @@ public ViewFrustum getFrustum() {
}

@Override
public Matrix getRotation() {
Transform transform = getOwner().getPhysics().getTransform().copy().translate(0, 2, 0);
return MatrixMath.createRotated(transform.getRotation());
public Matrix4 getRotation() {
Transform transform = getOwner().getPhysics().getTransformRender();
return Matrix4.createRotation(transform.getRotation());
}
}
Expand Up @@ -35,7 +35,7 @@
import org.spout.api.event.entity.EntityCollideEvent;
import org.spout.api.event.entity.EntityInteractEvent;
import org.spout.api.event.entity.EntitySpawnEvent;
import org.spout.api.math.GenericMath;
import org.spout.math.GenericMath;

/**
* Represents a component who shapes the logic behind an {@link Entity}.
Expand Down
Expand Up @@ -30,9 +30,9 @@
import org.spout.api.geo.cuboid.Block;
import org.spout.api.geo.discrete.Transform;
import org.spout.api.material.block.BlockFace;
import org.spout.api.math.QuaternionMath;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;
import org.spout.api.util.BlockIterator;
import org.spout.math.imaginary.Quaternion;

/**
* A component allowing a player to interact with a block
Expand Down Expand Up @@ -95,7 +95,7 @@ public Block getLastEmpty() {
public BlockIterator getAlignedBlocks() {
Transform ptr = player.getPhysics().getTransform();
Transform tr = new Transform();
tr.setRotation(QuaternionMath.rotationTo(Vector3.FORWARD, ptr.getRotation().getDirection().multiply(-1)));
tr.setRotation(Quaternion.fromRotationTo(Vector3.FORWARD, ptr.getRotation().getDirection().mul(-1)));
tr.setPosition(ptr.getPosition());
return new BlockIterator(player.getWorld(), tr, range);
}
Expand Down
Expand Up @@ -38,7 +38,7 @@
import org.spout.api.entity.Entity;
import org.spout.api.geo.discrete.Point;
import org.spout.api.geo.discrete.Transform;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;
import org.spout.api.util.concurrent.SpinLock;

public class NavigationComponent extends EntityComponent {
Expand Down
Expand Up @@ -42,7 +42,6 @@
import org.spout.api.Spout;
import org.spout.api.entity.Entity;
import org.spout.api.entity.Player;
import org.spout.api.event.Listener;
import org.spout.api.event.ProtocolEvent;
import org.spout.api.geo.LoadOption;
import org.spout.api.geo.World;
Expand All @@ -52,12 +51,11 @@
import org.spout.api.map.DefaultedKey;
import org.spout.api.map.DefaultedKeyImpl;
import org.spout.api.math.IntVector3;
import org.spout.api.math.Vector3;
import org.spout.api.protocol.Message;
import org.spout.api.protocol.reposition.NullRepositionManager;
import org.spout.api.protocol.reposition.RepositionManager;
import org.spout.api.util.OutwardIterator;

import org.spout.math.vector.Vector3;

/**
* The networking behind {@link org.spout.api.entity.Entity}s.
*/
Expand Down Expand Up @@ -214,7 +212,8 @@ public final void callProtocolEvent(final ProtocolEvent event, final boolean ign
}
final Point otherPosition = player.getPhysics().getPosition();
//TODO: Verify this math
if (position.subtract(otherPosition).fastLength() > player.getNetwork().getSyncDistance()) {
final int syncDistance = player.getNetwork().getSyncDistance();
if (position.sub(otherPosition).lengthSquared() > syncDistance * syncDistance) {
continue;
}
for (final Message message : messages) {
Expand All @@ -239,7 +238,7 @@ public final void callProtocolEvent(final ProtocolEvent event, final Player... p
}

/**
* Calls a {@link ProtocolEvent} for all the given {@link Enitity}s. For every {@link Entity} that is a {@link Player}, any messages from the event will be sent to that Player's session. Any
* Calls a {@link ProtocolEvent} for all the given {@link org.spout.api.entity.Entity}s. For every {@link Entity} that is a {@link Player}, any messages from the event will be sent to that Player's session. Any
* non-player entities can use the event for custom handling.
*
* @param event to send
Expand Down Expand Up @@ -326,7 +325,7 @@ protected void updateObserver() {
chunk.refreshObserver(getOwner());
observing.add(chunk);
} else {
ungenerated.add(new Vector3(v));
ungenerated.add(v.toVector3());
observeChunksFailed = true;
}
}
Expand Down
Expand Up @@ -29,11 +29,10 @@
import org.spout.api.geo.World;
import org.spout.api.geo.discrete.Point;
import org.spout.api.geo.discrete.Transform;
import org.spout.api.math.Quaternion;
import org.spout.api.math.Vector3;
import org.spout.math.vector.Vector3;
import org.spout.api.util.thread.annotation.SnapshotRead;
import org.spout.api.util.thread.annotation.Threadsafe;

import org.spout.math.imaginary.Quaternion;
import org.spout.physics.collision.shape.CollisionShape;

/**
Expand Down Expand Up @@ -207,7 +206,7 @@ public World getWorld() {
public abstract PhysicsComponent translate(Vector3 translation);

/**
* Rotates this {@link org.spout.api.entity.Entity} from its current {@link org.spout.api.math.Quaternion} to the Quaternion that is the addition of the Quaternion provided. <p/> For example, if I
* Rotates this {@link org.spout.api.entity.Entity} from its current {@link org.spout.math.imaginary.Quaternion} to the Quaternion that is the addition of the Quaternion provided. <p/> For example, if I
* want to rotate an Entity upwards (which is moving its yaw), I would do a rotate(new Quaternion(0, 1, 0, 0)); <p> Bear in mind, doing a rotate does so without physics and instead the rotation of
* the Entity will be directly set within its physics transform. This method always syncs the change to the client.
*
Expand Down
Expand Up @@ -52,7 +52,6 @@
import org.spout.api.geo.discrete.Transform;
import org.spout.api.io.store.simple.MemoryStore;
import org.spout.api.math.IntVector3;
import org.spout.api.math.Vector3;
import org.spout.api.protocol.ClientSession;
import org.spout.api.protocol.ServerSession;
import org.spout.api.protocol.Session;
Expand Down
Expand Up @@ -28,10 +28,11 @@

import org.spout.api.map.DefaultedKey;
import org.spout.api.map.DefaultedKeyImpl;
import org.spout.api.math.Vector3;
import org.spout.api.render.Font;
import org.spout.api.render.SpoutRenderMaterials;

import org.spout.math.vector.Vector3;

public class TextModelComponent extends EntityComponent {
private static final DefaultedKey<String> KEY_TEXT = new DefaultedKeyImpl<>("entity-text", "(your text here)");
private static final DefaultedKey<Font> KEY_FONT = new DefaultedKeyImpl<>("font", SpoutRenderMaterials.DEFAULT_FONT);
Expand Down
5 changes: 3 additions & 2 deletions api/src/main/java/org/spout/api/data/Data.java
Expand Up @@ -31,7 +31,8 @@
import org.spout.api.map.DefaultedKey;
import org.spout.api.map.DefaultedKeyImpl;
import org.spout.api.material.BlockMaterial;
import org.spout.api.math.Vector3;

import org.spout.math.vector.Vector3;

/**
* Common default data mappings one could expect each game to have. These are used instead of strings when retrieving values from an object that holds a datatable. IF you wish to provide your own keys
Expand All @@ -41,5 +42,5 @@ public interface Data {
public static final DefaultedKey<ItemStack> HELD_ITEM = new ItemStackDefaultedKey("held_item", BlockMaterial.AIR, 1);
public static final DefaultedKey<String> HELD_MATERIAL_NAME = new DefaultedKeyImpl<>("held_material_name", BlockMaterial.AIR.getName());
public static final DefaultedKey<String> NAME = new DefaultedKeyImpl<>("name", "");
public static final DefaultedKey<Vector3> VELOCITY = new DefaultedKeyImpl<>("velocity", Vector3.ONE);
public static final DefaultedKey<Vector3> VELOCITY = new DefaultedKeyImpl<>("velocity", new Vector3(1, 1, 1));
}
2 changes: 1 addition & 1 deletion api/src/main/java/org/spout/api/data/ValueHolderBase.java
Expand Up @@ -32,8 +32,8 @@
import java.util.Collections;
import java.util.List;

import org.spout.api.math.GenericMath;
import org.spout.cereal.config.serialization.Serialization;
import org.spout.math.GenericMath;

public class ValueHolderBase implements ValueHolder {
private final ValueHolder actualValue;
Expand Down

0 comments on commit e96aa1b

Please sign in to comment.