Package edu.cmu.cs.stage3.math

Examples of edu.cmu.cs.stage3.math.Quaternion


            // defined as quaternion
            float x = parseFloat(attribs.getValue("x"));
            float y = parseFloat(attribs.getValue("y"));
            float z = parseFloat(attribs.getValue("z"));
            float w = parseFloat(attribs.getValue("w"));
            return new Quaternion(x, y, z, w);
        } else if (attribs.getValue("qx") != null) {
            // defined as quaternion with prefix "q"
            float x = parseFloat(attribs.getValue("qx"));
            float y = parseFloat(attribs.getValue("qy"));
            float z = parseFloat(attribs.getValue("qz"));
            float w = parseFloat(attribs.getValue("qw"));
            return new Quaternion(x, y, z, w);
        } else if (attribs.getValue("angle") != null) {
            // defined as angle + axis
            float angle = parseFloat(attribs.getValue("angle"));
            float axisX = parseFloat(attribs.getValue("axisX"));
            float axisY = parseFloat(attribs.getValue("axisY"));
            float axisZ = parseFloat(attribs.getValue("axisZ"));
            Quaternion q = new Quaternion();
            q.fromAngleAxis(angle, new Vector3f(axisX, axisY, axisZ));
            return q;
        } else {
            // defines as 3 angles along XYZ axes
            float angleX = parseFloat(attribs.getValue("angleX"));
            float angleY = parseFloat(attribs.getValue("angleY"));
            float angleZ = parseFloat(attribs.getValue("angleZ"));
            Quaternion q = new Quaternion();
            q.fromAngles(angleX, angleY, angleZ);
            return q;
        }
    }
View Full Code Here


            // apply the node's world transform on the light..
            root.updateGeometricState();
            if (light != null) {
                if (light instanceof DirectionalLight) {
                    DirectionalLight dl = (DirectionalLight) light;
                    Quaternion q = node.getWorldRotation();
                    Vector3f dir = dl.getDirection();
                    q.multLocal(dir);
                    dl.setDirection(dir);
                } else if (light instanceof PointLight) {
                    PointLight pl = (PointLight) light;
                    Vector3f pos = node.getWorldTranslation();
                    pl.setPosition(pos);
                } else if (light instanceof SpotLight) {
                    SpotLight sl = (SpotLight) light;

                    Vector3f pos = node.getWorldTranslation();
                    sl.setPosition(pos);

                    Quaternion q = node.getWorldRotation();
                    Vector3f dir = sl.getDirection();
                    q.multLocal(dir);
                    sl.setDirection(dir);
                }
            }
            light = null;
        }
View Full Code Here

    public AbstractBlenderHelper(String blenderVersion, BlenderContext blenderContext) {
        this.blenderVersion = Integer.parseInt(blenderVersion);
        this.blenderContext = blenderContext;
        fixUpAxis = blenderContext.getBlenderKey().isFixUpAxis();
        if (fixUpAxis) {
            upAxisRotationQuaternion = new Quaternion().fromAngles(-FastMath.HALF_PI, 0, 0);
        }
    }
View Full Code Here

    public void endElement(String uri, String name, String qName) {
        if (qName.equals("translate") || qName.equals("position") || qName.equals("scale")) {
        } else if (qName.equals("axis")) {
        } else if (qName.equals("rotate") || qName.equals("rotation")) {
            rotation = new Quaternion();
            axis.normalizeLocal();
            rotation.fromAngleNormalAxis(angle, axis);
            angle = 0;
            axis = null;
        } else if (qName.equals("bone")) {
View Full Code Here

        }

        Matrix4f boneLocalMatrix = parent == null ? boneMatrixInModelSpace : parent.boneMatrixInModelSpace.invert().multLocal(boneMatrixInModelSpace);

        Vector3f poseLocation = parent == null || !this.is(CONNECTED_TO_PARENT) ? boneLocalMatrix.toTranslationVector() : new Vector3f(0, parent.length, 0);
        Quaternion rotation = boneLocalMatrix.toRotationQuat().normalizeLocal();
        Vector3f scale = boneLocalMatrix.toScaleVector();

        bone.setBindTransforms(poseLocation, rotation, scale);
        for (BoneContext child : children) {
            bone.addChild(child.buildBone(bones, skeletonOwnerOma, blenderContext));
View Full Code Here

    SpatialFactory sf = new SpatialFactory();
   
    Asteroid a = SpaceobjectFactory.eINSTANCE.createAsteroid();
    a.setLocation(new Vector3f(0,0,20));
    a.setRotation(new Quaternion());
    a.setId(2);
   
    sf.addControlledObject(a, loadNow);

//    SoundFactory sof = new SoundFactory(assetManager, objectController);
View Full Code Here

        SpaceObject so = SpaceobjectFactory.eINSTANCE.createAsteroid();
       
        so.setId(nextID++);
        so.setLocation(pos);
        so.setName(name);
        so.setRotation(new Quaternion());
        so.setLinearVelocity(new Vector3f());
        so.setAngularVelocity(new Quaternion());

        Node fighter = new Node(name);
        ControlledSpaceObject cso = new ControlledSpaceObject(so, fighter);
        cso.setDebugDisplay(name);
        cso.setGameThreadCallback(new SpatialUpdater(cso));
View Full Code Here

      else if (velocityInputTime < 0)
        targetSpeed -= 0.5f;

      // Velocity
      Vector3f currentVelocity = new Vector3f(vehicleControl.getLinearVelocity());
      Quaternion currentRotation = new Quaternion(vehicleControl.getPhysicsRotation());

      Vector3f targetVelocity = currentRotation.mult(new Vector3f(0f, 0f, targetSpeed));

      float xDiff = currentVelocity.x - targetVelocity.x;
      float zDiff = currentVelocity.z - targetVelocity.z;
      Vector3f diffVector = new Vector3f(xDiff, 0f, zDiff);

      // diffVector nach z drehen
      diffVector = currentRotation.inverse().mult(diffVector);

      float zThrust = 0f, yThrust, xThrust = 0f;
      float engine = .1f, thrust = .1f;

      if (diffVector.z < 0) { // accelerate
        zThrust = (-diffVector.z > engine) ? engine : -diffVector.z;
      } else if (diffVector.z > 0) { // brake
        zThrust = (diffVector.z > engine) ? -engine : -diffVector.z;
      }

      if (diffVector.x < 0) { // accelerate
        xThrust = (-diffVector.x > engine) ? engine : -diffVector.x;
      } else if (diffVector.x > 0) { // brake
        xThrust = (diffVector.x > engine) ? -engine : -diffVector.x;
      }

      Vector3f hemisphereVector = new Vector3f(0f, 0f, 1f);
      hemisphereVector = currentRotation.multLocal(hemisphereVector);

      xThrust = (hemisphereVector.x > 0) ? xThrust : xThrust;
      zThrust = (hemisphereVector.z > 0) ? zThrust : zThrust;

      Vector3f impulse = new Vector3f(xThrust, 0f, zThrust);

      vehicleControl.applyImpulse(currentRotation.mult(impulse), Vector3f.ZERO);

      // // Velocity

      // System.out.println(vehicleControl.getPhysicsRotation().mult(v));
      // System.out.println("tar: " + targetVelocity);
View Full Code Here

    Spatial character = app.getAssetManager().loadModel("character/" + id + "/Mesh.mesh.xml");
    character.setLocalTranslation(0f, 0f, 5f);
    Material mat_character = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
    mat_character.setTexture("DiffuseMap", app.getAssetManager().loadTexture("character/male/male.png"));
    character.setMaterial(mat_character);
    Quaternion rotate = new Quaternion();
    rotate.fromAngleAxis(-FastMath.PI / 2, new Vector3f(1, 0, 0));
    character.setLocalRotation(rotate);
    characterNode.attachChild(character);
    app.getRootNode().attachChild(characterNode);

    System.out.println(cam.getDirection());
View Full Code Here

      if(KeyState.containsKey("Up") && KeyState.get("Up"))
        CurrentRotation.x--;
      if(KeyState.containsKey("Down") && KeyState.get("Down"))
        CurrentRotation.x++;

      Quaternion q = new Quaternion();//Quaternion.DIRECTION_Z;
      q.fromAngles(Rotation.x, Rotation.y, Rotation.z);
     
     
      q.mult(CurrentMovement, CurrentMovement);
     
      Position.addLocal(CurrentMovement.multLocal(MovementSpeed * tpf));
      Rotation.addLocal(CurrentRotation.multLocal(RotationSpeed * tpf));
     
      Camera.setLocation(Position);
      Camera.lookAt(q.mult(View).addLocal(Position), q.mult(Up));
     
      CurrentMovement.set(0,0,0);
      CurrentRotation.set(0,0,0);
    }
View Full Code Here

TOP

Related Classes of edu.cmu.cs.stage3.math.Quaternion

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.