Example usage for com.badlogic.gdx.math Vector2 Vector2

List of usage examples for com.badlogic.gdx.math Vector2 Vector2

Introduction

In this page you can find the example usage for com.badlogic.gdx.math Vector2 Vector2.

Prototype

public Vector2(float x, float y) 

Source Link

Document

Constructs a vector with the given components

Usage

From source file:CB_UI.GL_UI.Views.MapView.java

License:Open Source License

/**
 * setNewSettings//from  w  w  w. j  a v  a 2 s .  c o m
 * 
 */
@Override
public void setNewSettings(int InitialFlags) {
    if ((InitialFlags & INITIAL_SETTINGS) != 0) {
        showRating = Mode == MapMode.Compass ? false : Config.MapShowRating.getValue();
        showDT = Mode == MapMode.Compass ? false : Config.MapShowDT.getValue();
        showTitles = Mode == MapMode.Compass ? false : Config.MapShowTitles.getValue();
        hideMyFinds = Config.MapHideMyFinds.getValue();
        showCompass = Mode == MapMode.Compass ? false : Config.MapShowCompass.getValue();
        showDirectLine = Mode == MapMode.Compass ? false : Config.ShowDirektLine.getValue();
        showAllWaypoints = Mode == MapMode.Compass ? false : Config.ShowAllWaypoints.getValue();
        showAccuracyCircle = Mode == MapMode.Compass ? false : Config.ShowAccuracyCircle.getValue();
        showMapCenterCross = Mode == MapMode.Compass ? false : Config.ShowMapCenterCross.getValue();

        if (Mode == MapMode.Track) {
            showMapCenterCross = true;
            setMapState(MapState.FREE);
        }

        if (info != null)
            info.setVisible(showCompass);

        if (InitialFlags == INITIAL_ALL) {
            iconFactor = Config.MapViewDPIFaktor.getValue();

            int setAktZoom = Mode == MapMode.Compass ? Config.lastZoomLevel.getValue()
                    : Config.lastZoomLevel.getValue();
            int setMaxZoom = Mode == MapMode.Compass ? Config.CompassMapMaxZommLevel.getValue()
                    : Config.OsmMaxLevel.getValue();
            int setMinZoom = Mode == MapMode.Compass ? Config.CompassMapMinZoomLevel.getValue()
                    : Config.OsmMinLevel.getValue();

            aktZoom = setAktZoom;
            zoomBtn.setMaxZoom(setMaxZoom);
            zoomBtn.setMinZoom(setMinZoom);
            zoomBtn.setZoom(aktZoom);

            zoomScale.setMaxZoom(setMaxZoom);
            zoomScale.setMinZoom(setMinZoom);

            if (Mode == MapMode.Compass) {
                // Berechne die darstellbare Entfernung fr jedes ZoomLevel
                DistanceZoomLevel = new TreeMap<Integer, Integer>();

                int posiblePixel = (int) this.getHalfHeight();

                for (int i = setMaxZoom; i > setMinZoom; i--) {
                    float PixelForZoomLevel = getPixelsPerMeter(i);
                    DistanceZoomLevel.put(i, (int) (posiblePixel / PixelForZoomLevel));
                }
            }

        }
    }

    if ((InitialFlags & INITIAL_THEME) != 0) {
        mapsForgeThemePath = null;
        boolean useInvertNightTheme = false;
        if (CarMode) {
            ManagerBase.Manager.textScale = ManagerBase.DEFAULT_TEXT_SCALE * 1.35f;
            if (Config.nightMode.getValue()) {
                if (!setTheme(Config.MapsforgeCarNightTheme.getValue())) {
                    useInvertNightTheme = true;
                    if (!setTheme(Config.MapsforgeCarDayTheme.getValue())) {
                        mapsForgeThemePath = ManagerBase.INTERNAL_CAR_THEME;
                    }
                }
            } else {
                if (!setTheme(Config.MapsforgeCarDayTheme.getValue())) {
                    mapsForgeThemePath = ManagerBase.INTERNAL_CAR_THEME;
                }
            }
        } else {
            ManagerBase.Manager.textScale = ManagerBase.DEFAULT_TEXT_SCALE;
            if (Config.nightMode.getValue()) {
                if (!setTheme(Config.MapsforgeNightTheme.getValue())) {
                    useInvertNightTheme = true;
                    setTheme(Config.MapsforgeDayTheme.getValue());
                    // else themePath = null : defaults to internal RenderTheme OSMARENDER
                }
            } else {
                setTheme(Config.MapsforgeDayTheme.getValue());
                // else themePath = null : defaults to internal RenderTheme OSMARENDER
            }
        }
        ManagerBase.Manager.setRenderTheme(mapsForgeThemePath, useInvertNightTheme);
    }

    if ((InitialFlags & INITIAL_WP_LIST) != 0) {
        if (mapCacheList != null) {
            MapViewCacheListUpdateData data = new MapViewCacheListUpdateData(screenToWorld(new Vector2(0, 0)),
                    screenToWorld(new Vector2(mapIntWidth, mapIntHeight)), aktZoom, true);
            this.hideMyFinds = Config.MapHideMyFinds.getValue();
            data.hideMyFinds = this.hideMyFinds;
            this.showAllWaypoints = Mode == MapMode.Compass ? false : Config.ShowAllWaypoints.getValue();
            data.showAllWaypoints = this.showAllWaypoints;
            mapCacheList.update(data);
        }

    }

    //preload only if Mapsforge layer selected
    if (mapTileLoader != null && mapTileLoader.getCurrentLayer() != null
            && mapTileLoader.getCurrentLayer().isMapsForge()) {
        if (!MapTileLoderPreInitial) {
            MapTileLoderPreInitial = true;

            Thread preLoadThread = new Thread(new Runnable() {

                @Override
                public void run() {
                    int halfMapIntWidth = mapIntWidth / 2;
                    int halfMapIntHeight = mapIntHeight / 2;

                    synchronized (screenCenterT) {
                        screenCenterW.x = screenCenterT.x;
                        screenCenterW.y = screenCenterT.y;
                    }

                    // preload only one Tile(the Tile on Center)
                    loVector.set(halfMapIntWidth, halfMapIntHeight);
                    lo.set(screenToDescriptor(loVector, aktZoom, lo));

                    MapTileLoderPreInitialAtWork = true;
                    mapTileLoader.loadTiles(MapView.this, lo, lo, aktZoom);
                    Thread checkPreLoadReadyThread = new Thread(new Runnable() {

                        @Override
                        public void run() {
                            while (true) {
                                if (mapTileLoader.LoadedTilesSize() > 0) {
                                    break;
                                }
                                try {
                                    Thread.sleep(100);
                                } catch (InterruptedException e) {

                                }
                            }

                            MapTileLoderPreInitialAtWork = false;
                        }
                    });
                    checkPreLoadReadyThread.start();
                }
            });
            preLoadThread.start();
        }
    }
}

From source file:CB_UI.GL_UI.Views.MapViewCacheList.java

License:Open Source License

public void update(MapViewCacheListUpdateData data) {
    LastUpdateData = data;//from w w  w .  j  av  a2s  .c o  m
    this.showAllWaypoints = data.showAllWaypoints;
    this.hideMyFinds = data.hideMyFinds;

    if (data.point1 == null || data.point2 == null)
        return;

    if (state.get() == 4) {
        // der queueProcessor wurde gestoppt und muss neu gestartet werden
        StartQueueProcessor();
    }

    if (state.get() != 0) {
        // Speichere Update anfrage und fhre sie aus, wenn der queueProcessor wieder bereit ist!
        savedQuery = data;
        return;
    }

    if ((data.zoom == lastzoom) && (!data.doNotCheck)) {
        // wenn LastPoint == 0 muss eine neue Liste Berechnet werden!
        if (lastPoint1 != null && lastPoint2 != null) {
            // Prfen, ob berhaupt eine neue Liste berechnet werden mu
            if ((data.point1.x >= lastPoint1.x) && (data.point2.x <= lastPoint2.x)
                    && (data.point1.y >= lastPoint1.y) && (data.point2.y <= lastPoint2.y))
                return;
        }

    }

    // Bereich erweitern, damit von vorne herein gleiche mehr Caches geladen werden und diese Liste nicht so oft berechnet werden muss
    Vector2 size = new Vector2(data.point2.x - data.point1.x, data.point2.y - data.point1.y);
    data.point1.x -= size.x;
    data.point2.x += size.x;
    data.point1.y -= size.y;
    data.point2.y += size.y;

    this.lastzoom = data.zoom;
    lastPoint1 = data.point1;
    lastPoint2 = data.point2;

    this.zoom = data.zoom;
    this.point1 = data.point1;
    this.point2 = data.point2;
    state.set(1);
}

From source file:CB_UI.GL_UI.Views.TestViews.TrackListView.java

License:Open Source License

@Override
public boolean onTouchDown(int x, int y, int pointer, int button) {
    super.onTouchDown(x, y, pointer, button);

    // for (Iterator<GL_View_Base> iterator = childs.iterator(); iterator.hasNext();)
    for (Iterator<GL_View_Base> iterator = childs.reverseIterator(); iterator.hasNext();) {
        // Child View suchen, innerhalb derer Bereich der touchDown statt gefunden hat.
        GL_View_Base view = iterator.next();

        if (view instanceof TrackListViewItem) {
            if (view.contains(x, y)) {
                ((TrackListViewItem) view).lastItemTouchPos = new Vector2(x - view.getX(), y - view.getY());
            }/*  w ww. j ava2 s.c  o m*/
        }
    }
    return true;
}

From source file:CB_UI.RouteOverlay.java

License:Open Source License

public static void RenderRoute(Batch batch, MapView mapView) {

    int Zoom = mapView.getAktZoom();
    float yVersatz = mapView.ySpeedVersatz;

    if (aktCalcedZoomLevel != Zoom || mRoutesChanged) {// Zoom or Routes changed => calculate new Sprite Points

        // Log.debug(log, "Zoom Changed => Calc Track Points");

        mRoutesChanged = false;//from w  ww  .  j a  v a  2s.co  m
        aktCalcedZoomLevel = Zoom;
        if (DrawRoutes == null)
            DrawRoutes = new ArrayList<RouteOverlay.Route>();
        else
            DrawRoutes.clear();

        double tolerance = 0.01 * Math.exp(-1 * (Zoom - 11));
        Tolleranz = tolerance;

        for (int i = 0; i < Routes.size(); i++) {

            if (Routes.get(i) != null && Routes.get(i).ShowRoute) {
                addToDrawRoutes(tolerance, Routes.get(i), Zoom, false);
            }
        }

        if (GlobalCore.AktuelleRoute != null && GlobalCore.AktuelleRoute.ShowRoute) {
            addToDrawRoutes(tolerance, GlobalCore.AktuelleRoute, Zoom, false);
        }

    }

    // DrawedLineCount = 0;

    if (DrawRoutes != null && DrawRoutes.size() > 0) {
        for (Route rt : DrawRoutes) {

            Sprite ArrowSprite = rt.ArrowSprite;
            Sprite PointSprite = rt.PointSprite;
            float overlap = rt.overlap;
            ArrowSprite.setColor(rt.mColor);
            PointSprite.setColor(rt.mColor);
            float scale = UI_Size_Base.that.getScale();

            for (int ii = 0; ii < rt.Points.size() - 1; ii++) {

                double MapX1 = 256.0
                        * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, rt.Points.get(ii).X);
                double MapY1 = -256.0
                        * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, rt.Points.get(ii).Y);

                double MapX2 = 256.0
                        * Descriptor.LongitudeToTileX(MapTileLoader.MAX_MAP_ZOOM, rt.Points.get(ii + 1).X);
                double MapY2 = -256.0
                        * Descriptor.LatitudeToTileY(MapTileLoader.MAX_MAP_ZOOM, rt.Points.get(ii + 1).Y);

                Vector2 screen1 = mapView.worldToScreen(new Vector2((float) MapX1, (float) MapY1));
                Vector2 screen2 = mapView.worldToScreen(new Vector2((float) MapX2, (float) MapY2));

                screen1.y -= yVersatz;
                screen2.y -= yVersatz;

                CB_RectF chkRec = new CB_RectF(mapView);
                chkRec.setPos(0, 0);

                // chk if line on Screen
                if (chkRec.contains(screen1.x, screen1.y) || chkRec.contains(screen2.x, screen2.y)) {
                    DrawUtils.drawSpriteLine(batch, ArrowSprite, PointSprite, overlap * scale, screen1.x,
                            screen1.y, screen2.x, screen2.y);
                    // DrawedLineCount++;
                } else {// chk if intersection
                    if (chkRec.getIntersection(screen1, screen2, 2) != null) {
                        DrawUtils.drawSpriteLine(batch, ArrowSprite, PointSprite, overlap * scale, screen1.x,
                                screen1.y, screen2.x, screen2.y);
                        // DrawedLineCount++;
                    }

                    // the line is not on the screen
                }

            }

        }
    }
}

From source file:CB_UI_Base.GL_UI.Controls.Dialog.java

License:Open Source License

private void reziseContentBox() {

    if (margin <= 0)
        margin = UI_Size_Base.that.getMargin();

    if (mContent == null) {
        this.initialDialog();
        return;/*from  w  w w. j  a  v a  2s.  co m*/
    }

    mTitleHeight = 0;
    if (mTitle != null && !mTitle.equals("")) {
        mHasTitle = true;

        if (titleLabel == null) {
            titleLabel = new Label(mTitle);
        } else {
            if (!titleLabel.getText().equals(mTitle)) {
                titleLabel.setText(mTitle);
            }
        }
        titleLabel.setWidth(titleLabel.getTextWidth() + leftBorder + rightBorder);
        this.initRow();
        this.addLast(titleLabel, FIXED);

        mTitleHeight = titleLabel.getHeight();
        mTitleWidth = titleLabel.getWidth();
        mTitleWidth += rightBorder + leftBorder; // sonst sieht es bld aus
    }

    mContent.setWidth(this.getWidth() * 0.95f);
    mContent.setHeight((this.getHeight() - mHeaderHeight - mFooterHeight - mTitleHeight - margin));
    float centerversatzX = this.getHalfWidth() - mContent.getHalfWidth();
    float centerversatzY = mFooterHeight;// this.halfHeight - mContent.getHalfHeight();
    mContent.setPos(new Vector2(centerversatzX, centerversatzY));

}

From source file:CB_UI_Base.GL_UI.Controls.ZoomButtons.java

License:Open Source License

@Override
public boolean onTouchDown(int x, int y, int pointer, int button) {
    return touchDownTest(new Vector2(x, y));
}

From source file:CB_UI_Base.GL_UI.GL_View_Base.java

License:Open Source License

public final GL_View_Base touchDown(int x, int y, int pointer, int button) {
    // Achtung: dieser touchDown ist nicht virtual und darf nicht berschrieben werden!!!
    // das Ereignis wird dann in der richtigen View an onTouchDown bergeben!!!
    // touchDown liefert die View zurck, die dieses TochDown Ereignis angenommen hat
    GL_View_Base resultView = null;

    if (childs != null && childs.size() > 0) {
        try {/*from   w w  w .  j av  a2s  .c o m*/
            for (Iterator<GL_View_Base> iterator = childs.reverseIterator(); iterator.hasNext();) {
                // Child View suchen, innerhalb derer Bereich der touchDown statt gefunden hat.
                GL_View_Base view = iterator.next();

                // Invisible Views can not be clicked!
                if (view == null || !view.isVisible())
                    continue;
                if (!view.isEnabled())
                    continue;
                if (view.contains(x, y)) {
                    // touch innerhalb des Views
                    // -> Klick an das View weitergeben
                    lastTouchPos = new Vector2(x - view.getX(), y - view.getY());
                    resultView = view.touchDown(x - (int) view.getX(), y - (int) view.getY(), pointer, button);
                }

                if (resultView != null)
                    break;
            }
        } catch (Exception e) {
            return null;
        }
    }

    if (forceHandleTouchEvents || resultView == null) {

        // kein Klick in einem untergeordnetem View
        // -> hier behandeln
        boolean behandelt = onTouchDown(x, y, pointer, button);
        if (behandelt)
            resultView = this;
    }

    GL.that.renderOnce();
    return resultView;
}

From source file:CB_UI_Base.graphics.GL_Path.java

License:Open Source License

/**
 * Add a cubic bezier from the last point, approaching control points (x1,y1) and (x2,y2), and ending at (x3,y3). If no moveTo() call
 * has been made for this contour, the first point is automatically set to (0,0).
 * /*from w  w  w  . ja  va 2  s. c  o m*/
 * @param x1
 *            The x-coordinate of the 1st control point on a cubic curve
 * @param y1
 *            The y-coordinate of the 1st control point on a cubic curve
 * @param x2
 *            The x-coordinate of the 2nd control point on a cubic curve
 * @param y2
 *            The y-coordinate of the 2nd control point on a cubic curve
 * @param x3
 *            The x-coordinate of the end point on a cubic curve
 * @param y3
 *            The y-coordinate of the end point on a cubic curve
 */
@Override
public void cubicTo(float x1, float y1, float x2, float y2, float x3, float y3) {

    // calculate distance
    float distance = calcDistance(last[0], last[1], x1, y1);
    distance += calcDistance(x1, y1, x2, y2);
    distance += calcDistance(x2, y2, x3, y3);
    distance = Math.min(0.2f, 1 / (distance / MIN_SEGMENTH_LENGTH));

    if (items.length == 0) {
        throw new IllegalStateException("Missing initial moveTo()");
    }

    Vector2 vec0 = new Vector2(last[0], last[1]);
    Vector2 vec1 = new Vector2(x1, y1);
    Vector2 vec2 = new Vector2(x2, y2);
    Vector2 vec3 = new Vector2(x3, y3);

    for (float location = distance; !(location > 1); location += distance) {
        Vector2 out = new Vector2();
        Vector2 tmp = new Vector2();
        Bezier.cubic(out, location, vec0, vec1, vec2, vec3, tmp);
        lineTo(out.x, out.y);
    }
    lineTo(x3, y3);
}

From source file:CB_UI_Base.graphics.GL_Path.java

License:Open Source License

/**
 * Add a quadratic bezier from the last point, approaching control point (x1,y1), and ending at (x2,y2). If no moveTo() call has been
 * made for this contour, the first point is automatically set to (0,0).
 * //  ww w . ja va2  s .  c  o  m
 * @param x1
 *            The x-coordinate of the control point on a quadratic curve
 * @param y1
 *            The y-coordinate of the control point on a quadratic curve
 * @param x2
 *            The x-coordinate of the end point on a quadratic curve
 * @param y2
 *            The y-coordinate of the end point on a quadratic curve
 */
@Override
public void quadTo(float x1, float y1, float x2, float y2) {

    // calculate distance
    float distance = calcDistance(last[0], last[1], x1, y1);
    distance += calcDistance(x1, y1, x2, y2);
    distance = Math.min(0.25f, 1 / (distance / MIN_SEGMENTH_LENGTH));

    if (items.length == 0) {
        throw new IllegalStateException("Missing initial moveTo()");
    }

    Vector2 vec0 = new Vector2(last[0], last[1]);
    Vector2 vec1 = new Vector2(x1, y1);
    Vector2 vec2 = new Vector2(x2, y2);

    for (float location = 0; location < 1; location += distance) {
        Vector2 out = new Vector2();
        Vector2 tmp = new Vector2();
        Bezier.quadratic(out, location, vec0, vec1, vec2, tmp);
        lineTo(out.x, out.y);
    }
    lineTo(x2, y2);
}

From source file:CB_UI_Base.Math.GL_UISizes.java

License:Open Source License

/**
 * Berechnet die Positionen der UI-Elemente
 *///from  w  w w. ja  v  a2  s . co m
private static void calcPos() {
    Log.debug(log, "GL_UISizes.calcPos()");

    float w = Global.isTab ? UI_Right.getWidth() : UI_Left.getWidth();
    float h = Global.isTab ? UI_Right.getHeight() : UI_Left.getHeight();

    Info.setPos(new Vector2(margin, (h - margin - Info.getHeight())));

    Float CompassMargin = (Info.getHeight() - Compass.getWidth()) / 2;

    Compass.setPos(new Vector2(Info.getX() + CompassMargin, Info.getY() + infoShadowHeight + CompassMargin));

    Toggle.setPos(new Vector2((w - margin - Toggle.getWidth()), h - margin - Toggle.getHeight()));

    ZoomBtn.setPos(new Vector2((w - margin - ZoomBtn.getWidth()), margin));

    InfoLine1.x = Compass.getMaxX() + margin;
    GlyphLayout bounds;
    if (Fonts.getNormal() != null) {
        bounds = new GlyphLayout();
        bounds.setText(Fonts.getSmall(), "52 34,806N ");
    } else {
        bounds = new GlyphLayout();
        bounds.height = 20;
        bounds.width = 100;
    }

    InfoLine2.x = Info.getX() + Info.getWidth() - bounds.width - (margin * 2);

    Float T1 = Info.getHeight() / 4;

    InfoLine1.y = Info.getMaxY() - T1;
    InfoLine2.y = Info.getY() + T1 + bounds.height;

    // Aufrumen
    CompassMargin = null;

}