Search in sources :

Example 46 with Quat4f

use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.

the class RotationTest method testRotateSideYaw.

@Test
public void testRotateSideYaw() {
    Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_90);
    Quat4f rot = rotation.getQuat4f();
    Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT));
    assertEquals(Side.LEFT, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.FRONT));
    assertEquals(Side.TOP, Rotation.rotate(Yaw.CLOCKWISE_90).rotate(Side.TOP));
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f) Test(org.junit.Test)

Example 47 with Quat4f

use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.

the class RotationTest method testRotateMixed.

@Test
public void testRotateMixed() {
    Rotation rotation = Rotation.rotate(Yaw.CLOCKWISE_180, Pitch.CLOCKWISE_90, Roll.CLOCKWISE_90);
    Quat4f rot = rotation.getQuat4f();
    Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT));
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f) Test(org.junit.Test)

Example 48 with Quat4f

use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.

the class RotationTest method testRotateSidePitch.

@Test
public void testRotateSidePitch() {
    Rotation rotation = Rotation.rotate(Pitch.CLOCKWISE_90);
    Quat4f rot = rotation.getQuat4f();
    Vector3f dir = rot.rotate(Side.FRONT.toDirection().getVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.FRONT));
    assertEquals(Side.TOP, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.FRONT));
    assertEquals(Side.RIGHT, Rotation.rotate(Pitch.CLOCKWISE_90).rotate(Side.RIGHT));
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f) Test(org.junit.Test)

Example 49 with Quat4f

use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.

the class RotationTest method testRotateSideRoll.

@Test
public void testRotateSideRoll() {
    Rotation rotation = Rotation.rotate(Roll.CLOCKWISE_90);
    Quat4f rot = rotation.getQuat4f();
    Vector3f dir = rot.rotate(Side.TOP.toDirection().getVector3f(), new Vector3f());
    assertEquals(Direction.inDirection(dir).toSide(), rotation.rotate(Side.TOP));
    assertEquals(Side.LEFT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.TOP));
    assertEquals(Side.FRONT, Rotation.rotate(Roll.CLOCKWISE_90).rotate(Side.FRONT));
}
Also used : Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f) Test(org.junit.Test)

Example 50 with Quat4f

use of org.terasology.math.geom.Quat4f in project Terasology by MovingBlocks.

the class RecursiveTreeGeneratorLSystem method recurse.

public void recurse(CoreChunk view, Random rand, int posX, int posY, int posZ, float angleOffset, CharSequenceIterator axiomIterator, Vector3f position, Matrix4f rotation, Block bark, Block leaf, int depth, AbstractTreeGenerator treeGenerator) {
    Matrix4f tempRotation = new Matrix4f();
    while (axiomIterator.hasNext()) {
        char c = axiomIterator.nextChar();
        switch(c) {
            case 'G':
            case 'F':
                // Tree trunk
                treeGenerator.safelySetBlock(view, posX + (int) position.x + 1, posY + (int) position.y, posZ + (int) position.z, bark);
                treeGenerator.safelySetBlock(view, posX + (int) position.x - 1, posY + (int) position.y, posZ + (int) position.z, bark);
                treeGenerator.safelySetBlock(view, posX + (int) position.x, posY + (int) position.y, posZ + (int) position.z + 1, bark);
                treeGenerator.safelySetBlock(view, posX + (int) position.x, posY + (int) position.y, posZ + (int) position.z - 1, bark);
                // Generate leaves
                if (depth > 1) {
                    int size = 1;
                    for (int x = -size; x <= size; x++) {
                        for (int y = -size; y <= size; y++) {
                            for (int z = -size; z <= size; z++) {
                                if (Math.abs(x) == size && Math.abs(y) == size && Math.abs(z) == size) {
                                    continue;
                                }
                                treeGenerator.safelySetBlock(view, posX + (int) position.x + x + 1, posY + (int) position.y + y, posZ + z + (int) position.z, leaf);
                                treeGenerator.safelySetBlock(view, posX + (int) position.x + x - 1, posY + (int) position.y + y, posZ + z + (int) position.z, leaf);
                                treeGenerator.safelySetBlock(view, posX + (int) position.x + x, posY + (int) position.y + y, posZ + z + (int) position.z + 1, leaf);
                                treeGenerator.safelySetBlock(view, posX + (int) position.x + x, posY + (int) position.y + y, posZ + z + (int) position.z - 1, leaf);
                            }
                        }
                    }
                }
                Vector3f dir = new Vector3f(1f, 0f, 0f);
                rotation.transformVector(dir);
                position.add(dir);
                break;
            case '[':
                recurse(view, rand, posX, posY, posZ, angleOffset, axiomIterator, new Vector3f(position), new Matrix4f(rotation), bark, leaf, depth, treeGenerator);
                break;
            case ']':
                return;
            case '+':
                tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, 1f), angle + angleOffset), Vector3f.ZERO, 1.0f);
                rotation.mul(tempRotation);
                break;
            case '-':
                tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, 0f, -1f), angle + angleOffset), Vector3f.ZERO, 1.0f);
                rotation.mul(tempRotation);
                break;
            case '&':
                tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, 1f, 0f), angle + angleOffset), Vector3f.ZERO, 1.0f);
                rotation.mul(tempRotation);
                break;
            case '^':
                tempRotation = new Matrix4f(new Quat4f(new Vector3f(0f, -1f, 0f), angle + angleOffset), Vector3f.ZERO, 1.0f);
                rotation.mul(tempRotation);
                break;
            case '*':
                tempRotation = new Matrix4f(new Quat4f(new Vector3f(1f, 0f, 0f), angle), Vector3f.ZERO, 1.0f);
                rotation.mul(tempRotation);
                break;
            case '/':
                tempRotation = new Matrix4f(new Quat4f(new Vector3f(-1f, 0f, 0f), angle), Vector3f.ZERO, 1.0f);
                rotation.mul(tempRotation);
                break;
            default:
                // If we have already reached the maximum depth, don't ever bother to lookup in the map
                if (depth == maxDepth - 1) {
                    break;
                }
                LSystemRule rule = ruleSet.get(c);
                if (rule == null) {
                    break;
                }
                float weightedFailureProbability = TeraMath.pow(1f - rule.getProbability(), maxDepth - depth);
                if (rand.nextFloat() < weightedFailureProbability) {
                    break;
                }
                recurse(view, rand, posX, posY, posZ, angleOffset, new CharSequenceIterator(rule.getAxiom()), position, rotation, bark, leaf, depth + 1, treeGenerator);
        }
    }
}
Also used : LSystemRule(org.terasology.math.LSystemRule) Matrix4f(org.terasology.math.geom.Matrix4f) Vector3f(org.terasology.math.geom.Vector3f) Quat4f(org.terasology.math.geom.Quat4f) CharSequenceIterator(org.terasology.utilities.collection.CharSequenceIterator)

Aggregations

Quat4f (org.terasology.math.geom.Quat4f)50 Vector3f (org.terasology.math.geom.Vector3f)33 LocationComponent (org.terasology.logic.location.LocationComponent)16 EntityRef (org.terasology.entitySystem.entity.EntityRef)14 Matrix4f (org.terasology.math.geom.Matrix4f)9 ClientComponent (org.terasology.network.ClientComponent)7 BaseQuat4f (org.terasology.math.geom.BaseQuat4f)6 FloatBuffer (java.nio.FloatBuffer)4 Test (org.junit.Test)4 BaseVector3f (org.terasology.math.geom.BaseVector3f)4 ArrayList (java.util.ArrayList)3 EntityBuilder (org.terasology.entitySystem.entity.EntityBuilder)3 ReceiveEvent (org.terasology.entitySystem.event.ReceiveEvent)3 CharacterComponent (org.terasology.logic.characters.CharacterComponent)3 Lists (com.google.common.collect.Lists)2 TIntList (gnu.trove.list.TIntList)2 TIntArrayList (gnu.trove.list.array.TIntArrayList)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Arrays (java.util.Arrays)2