Package net.rim.device.api.math

Examples of net.rim.device.api.math.Vector3f


     * @param position
     *            The position vector for the character
     */
    SpriteGameCharacter(final String texture, final Animator animator,
            final Vector3f position) {
        super(TEXCOORDS, texture, new BoundingBox(new Vector3f(-1.0f, -1.0f,
                0.0f), new Vector3f(1.0f, 1.0f, 0.0f)), position);

        _transform.setScale(new Vector3f(DEFAULT_SCALE, DEFAULT_SCALE,
                DEFAULT_SCALE));

        _prevTransform = new Transform3D(_transform);
        _prevBounds = new BoundingBox();

View Full Code Here


     */
    public void reset() {
        super.reset();
        _isJumping = false;
        _ty = 0.0f;
        _transform.setScale(new Vector3f(SpriteGameCharacter.DEFAULT_SCALE,
                SpriteGameCharacter.DEFAULT_SCALE,
                SpriteGameCharacter.DEFAULT_SCALE));
    }
View Full Code Here

     *
     * @param texture
     *            The filename of the mesh's texture
     */
    public Sprite(final String texture) {
        this(TEXCOORDS, texture, null, new Vector3f(0.0f, 0.0f, 0.0f));
    }
View Full Code Here

        if (bounds == null) {
            final Vector3f[] vertices = new Vector3f[VERTICES.length / 3];

            for (int i = 0; i < vertices.length; i++) {
                vertices[i] =
                        new Vector3f(VERTICES[i * 3], VERTICES[i * 3 + 1],
                                VERTICES[i * 3 + 2]);
            }

            _originalBounds = new BoundingBox(vertices);
            _bounds = new BoundingBox((BoundingBox) _originalBounds);
View Full Code Here

     */
    public void setIsBatched(final GL11 gl, final boolean isBatched) {
        _isBatchedRender = isBatched;
        if (_isBatchedRender && _batch == null) {
            // Pre-transform the vertices before adding them to the batch
            final Vector3f v = new Vector3f();
            final float[] vertexFloatData = new float[VERTICES.length];
            for (int i = 0; i < VERTICES.length / 3; i++) {
                v.set(VERTICES[i * 3], VERTICES[i * 3 + 1], VERTICES[i * 3 + 2]);
                _transform.transformPoint(v);
                vertexFloatData[i * 3] = v.x;
                vertexFloatData[i * 3 + 1] = v.y;
                vertexFloatData[i * 3 + 2] = v.z;
            }
View Full Code Here

     */
    public void setIsBatched(final GL20 gl, final boolean isBatched) {
        _isBatchedRender = isBatched;
        if (_isBatchedRender && _batch == null) {
            // Pre-transform the vertices before adding them to the batch
            final Vector3f v = new Vector3f();
            final float[] vertexFloatData = new float[VERTICES.length];
            for (int i = 0; i < VERTICES.length / 3; i++) {
                v.set(VERTICES[i * 3], VERTICES[i * 3 + 1], VERTICES[i * 3 + 2]);
                _transform.transformPoint(v);
                vertexFloatData[i * 3] = v.x;
                vertexFloatData[i * 3 + 1] = v.y;
                vertexFloatData[i * 3 + 2] = v.z;
            }
View Full Code Here

    SpriteGameGLField(final int glVersion) {
        super(glVersion);

        _glVersion = glVersion;

        final Vector3f translation = new Vector3f(-40.0f, -4.0f, 0.0f);

        // Set up the win sprite
        _win = new Sprite("win.png");
        _win._transform.setScale(new Vector3f(5.0f, 5.0f, 5.0f));
        _win._transform.setTranslation(translation);

        // Set up the lose sprite
        _lose = new Sprite("lose.png");
        _lose._transform.setScale(new Vector3f(5.0f, 5.0f, 5.0f));
        _lose._transform.setTranslation(translation);

        _timeSource = new TimeSource();
        _timeSource.start();
        _animator = new Animator(0, _timeSource);
View Full Code Here

        // Get the character's corners
        final Vector3f[] corners = new Vector3f[8];

        for (int i = 0; i < corners.length; i++) {
            corners[i] = new Vector3f();
        }
        bounds.getCorners(corners, 0);

        final float charTop = corners[0].y;
        final float charBottom = corners[1].y;
        final float charLeft = corners[0].x;
        final float charRight = corners[2].x;

        prevBounds.getCorners(corners, 0);
        final float prevCharTop = corners[0].y;
        final float prevCharBottom = corners[1].y;
        final float prevCharLeft = corners[0].x;
        final float prevCharRight = corners[2].x;

        final Vector3f characterCenter =
                new Vector3f((charLeft + charRight) / 2.0f,
                        (charTop + charBottom) / 2.0f, 0.0f);

        // Die if you fell off the level
        if (characterCenter.y < -20.0f) {
            return -1;
        }

        // Detect collision with the level end object
        boundsLevel = _levelGoal.getBounds();
        if (bounds.intersects(boundsLevel)) {
            _character.addMovementRestriction(SpriteGameCharacter.MOVE_DOWN
                    | SpriteGameCharacter.MOVE_UP
                    | SpriteGameCharacter.MOVE_LEFT
                    | SpriteGameCharacter.MOVE_RIGHT);
            return 1;
        }

        // Detect collisions with obstacles
        int count = _enemies.size();

        for (int i = 0; i < count; i++) {
            boundsLevel = ((Sprite) _enemies.elementAt(i)).getBounds();
            if (bounds.intersects(boundsLevel)) {
                _character.addMovementRestriction(SpriteGameCharacter.MOVE_DOWN
                        | SpriteGameCharacter.MOVE_UP
                        | SpriteGameCharacter.MOVE_LEFT
                        | SpriteGameCharacter.MOVE_RIGHT);
                return -1;
            }
        }

        _character.clearMovementRestrictions();

        // Detect collisions with blocks and calculate the character's movement
        // restrictions
        BoundingBox tileBounds;
        count = _tiles.size();
        Sprite tile;

        for (int i = 0; i < count; i++) {
            tile = (Sprite) _tiles.elementAt(i);
            tileBounds = (BoundingBox) tile.getBounds();
            if (bounds.intersects(tileBounds)) {
                // Calculate the center point of the block's bounding box
                final Vector3f min = new Vector3f();
                final Vector3f max = new Vector3f();
                tileBounds.getMin(min);
                tileBounds.getMax(max);
                final Vector3f blockCenter = new Vector3f(min);
                blockCenter.add(max);
                blockCenter.scale(0.5f);

                // Get character scale
                final Vector3f s = new Vector3f();
                _character._transform.getScale(s);

                // Determine which way(s) the character's
                // movement should be restricted. We also set the character's
                // translation vector
                // so that it does not visibly intersect the blocks.
                final float tileTop = max.y;
                final float tileBottom = min.y;
                final float tileLeft = min.x;
                final float tileRight = max.x;

                final float tileMidX = (tileLeft + tileRight) / 2.0f;
                final float tileMidY = (tileBottom + tileTop) / 2.0f;

                final Vector3f v = new Vector3f();

                // If character's top or bottom is between tile's
                // top and bottom, restrict horizontally
                if (charTop < tileTop - 0.1f && charTop > tileBottom + 0.1f
                        || charBottom > tileBottom + 0.1f
View Full Code Here

            // Add tiles for the amount of times that the tile should be
            // repeated
            for (int i = 0; i < repeat; i++) {
                final Sprite tile =
                        new Sprite(texture, new Vector3f(-11.0f + (pos[0] + i)
                                * 2.0f, -11.0f + pos[1] * 2.0f, 0.0f));
                tile._transform.scale(scale);
                _tiles.addElement(tile);
            }
        }
View Full Code Here

            Sprite enemy;
            Bounds bounds = null;

            if (texture.equals("obstacle_ball.png")) {
                bounds =
                        new BoundingBox(new Vector3f(-0.9f, -0.9f, 0.0f),
                                new Vector3f(0.9f, 0.9f, 0.0f));
            } else if (texture.equals("obstacle_spikewheel.png")) {
                bounds = new BoundingSphere(new Vector3f(), 0.75f);
            }

            enemy =
                    new Sprite(texture, bounds, new Vector3f(-11.0f + pos[0]
                            * 2.0f, -11.0f + pos[1] * 2.0f, 0.0f));
            enemy._transform.scale(scale);
            _enemies.addElement(enemy);
        }
View Full Code Here

TOP

Related Classes of net.rim.device.api.math.Vector3f

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.