Java Code Examples for com.badlogic.gdx.math.MathUtils#clamp()

The following examples show how to use com.badlogic.gdx.math.MathUtils#clamp() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FramePropertiesPersister.java    From gdx-texture-packer-gui with Apache License 2.0 6 votes vote down vote up
public static void loadFrameProperties(JFrame frame) {
    Preferences prefs = Gdx.app.getPreferences(PREF_NAME);

    DisplayMode displayMode = GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDisplayMode();
    int screenWidth = displayMode.getWidth();
    int screenHeight = displayMode.getHeight();

    int width = MathUtils.clamp(prefs.getInteger("width", frame.getSize().width), 320, screenWidth);
    int height = MathUtils.clamp(prefs.getInteger("height", frame.getSize().height), 320, screenHeight);
    int x = MathUtils.clamp(prefs.getInteger("x", frame.getLocation().x), 0, screenWidth - width);
    int y = MathUtils.clamp(prefs.getInteger("y", frame.getLocation().y), 0, screenHeight - height);
    int extendedState = prefs.getInteger("extendedState", frame.getExtendedState());

    frame.setSize(width, height);
    frame.setLocation(x, y);
    frame.setExtendedState(extendedState);
}
 
Example 2
Source File: Mini2DxOpenALAudioDevice.java    From mini2Dx with Apache License 2.0 5 votes vote down vote up
public void writeSamples (float[] samples, int offset, int numSamples) {
	if (bytes == null || bytes.length < numSamples * 2) bytes = new byte[numSamples * 2];
	int end = Math.min(offset + numSamples, samples.length);
	for (int i = offset, ii = 0; i < end; i++) {
		float floatSample = samples[i];
		floatSample = MathUtils.clamp(floatSample, -1f, 1f);
		int intSample = (int)(floatSample * 32767);
		bytes[ii++] = (byte)(intSample & 0xFF);
		bytes[ii++] = (byte)((intSample >> 8) & 0xFF);
	}
	writeSamples(bytes, 0, numSamples * 2);
}
 
Example 3
Source File: EngineF40.java    From uracer-kotd with Apache License 2.0 5 votes vote down vote up
@Override
public float getGlobalVolume () {
	float target_vol = 0;
	float scale_mt = 50;
	if (hasPlayer && progressData.hasTarget && !progressData.isWarmUp) {
		float d = progressData.playerDistance.get() - progressData.targetDistance.get();
		d = MathUtils.clamp(d, -scale_mt, scale_mt);
		d /= scale_mt; // normalized range
		float to_target = AMath.fixup(d);

		if (to_target < 0) {
			// player behind
			// fade out on distance from target (use tensive music meters scaling)
			float v = MathUtils.clamp(to_target + 1, 0, 1);
			target_vol = v;
		} else {
			// player heading the race
			target_vol = 1;
		}
	}

	// return .025f + 0.025f * volmul;
	// ivolume.set(0.1f + 0.05f * target_vol * player.carState.currSpeedFactor, 0.05f);
	float computedTarget = 0.1f - 0.05f * target_vol * player.carState.currSpeedFactor;
	ivolume.set(computedTarget, 0.005f);

	// Gdx.app.log("", "tv=" + ivolume.get());

	return ivolume.get();
}
 
Example 4
Source File: GameScreen.java    From riiablo with Apache License 2.0 5 votes vote down vote up
public void setDetails(Actor details, Item item, Actor parent, Actor slot) {
  if (this.details == details) return;
  this.details = details;
  if (slot != null) {
    details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY() + slot.getHeight(), Align.bottom | Align.center);
    tmpVec2.set(details.getX(), details.getY());
    parent.localToStageCoordinates(tmpVec2);
    tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
    tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
    details.setPosition(tmpVec2.x, tmpVec2.y);
    tmpVec2.set(slot.getX(), slot.getY());
    parent.localToStageCoordinates(tmpVec2);
    if (details.getY() < tmpVec2.y + slot.getHeight()) {
      details.setPosition(slot.getX() + slot.getWidth() / 2, slot.getY(), Align.top | Align.center);
      tmpVec2.set(details.getX(), details.getY());
      parent.localToStageCoordinates(tmpVec2);
      tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
      tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
      details.setPosition(tmpVec2.x, tmpVec2.y);
    }
  } else {
    details.setPosition(item.getX() + item.getWidth() / 2, item.getY(), Align.top | Align.center);
    tmpVec2.set(details.getX(), details.getY());
    parent.localToStageCoordinates(tmpVec2);
    tmpVec2.x = MathUtils.clamp(tmpVec2.x, 0, stage.getWidth()  - details.getWidth());
    tmpVec2.y = MathUtils.clamp(tmpVec2.y, 0, stage.getHeight() - details.getHeight());
    details.setPosition(tmpVec2.x, tmpVec2.y);
  }
}
 
Example 5
Source File: FieldViewManager.java    From homescreenarcade with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Saves scale and x and y offsets for use by world2pixel methods, avoiding repeated method
 * calls and math operations.
 */
public void cacheScaleAndOffsets() {
    zoom = maxZoom;
    // Don't zoom if game is over or multiball is active.
    if (zoom<=1.0f || !field.getGameState().isGameInProgress() || field.getBalls().size()>1) {
        zoom = 1.0f;
        cachedScale = getScale();
        // Center the entire table horizontally and put at at the top vertically.
        // Negative offsets so the 0 coordinate will be on the screen.
        float horizontalSpaceLeft = view.getWidth() - (field.getWidth() * cachedScale);
        cachedXOffset = (horizontalSpaceLeft > 0) ? -horizontalSpaceLeft/(2*cachedScale) : 0;
        float verticalSpaceLeft = view.getHeight() - (field.getHeight() * cachedScale);
        cachedYOffset = (verticalSpaceLeft > 0) ? -verticalSpaceLeft/cachedScale : 0;
    }
    else {
        List<Ball> balls = field.getBalls();
        float x=-1, y=-1;
        if (balls.size()==1) {
            Ball b = balls.get(0);
            x = b.getPosition().x;
            y = b.getPosition().y;
        }
        else {
            // use launch position
            List<Float> position = field.layout.getLaunchPosition();
            x = position.get(0);
            y = position.get(1);
        }
        float maxOffsetRatio = 1.0f - 1.0f/zoom;
        cachedXOffset = x - field.getWidth()/(2.0f * zoom);
        cachedXOffset = MathUtils.clamp(cachedXOffset, 0, field.getWidth()*maxOffsetRatio);

        cachedYOffset = y - field.getHeight()/(2.0f * zoom);
        cachedYOffset = MathUtils.clamp(cachedYOffset, 0, field.getHeight()*maxOffsetRatio);
        cachedScale = getScale();
    }
    cachedHeight = view.getHeight();
}
 
Example 6
Source File: CameraController.java    From talos with Apache License 2.0 5 votes vote down vote up
@Override
public boolean scrolled (int amount) {
	float currWidth = camera.viewportWidth * camera.zoom;
	float nextWidth = currWidth * (1f + amount * 0.1f);
	float nextZoom = nextWidth/camera.viewportWidth;
	camera.zoom = nextZoom;

	camera.zoom = MathUtils.clamp(camera.zoom, 0.1f, 10f);

	return true;
}
 
Example 7
Source File: Effect.java    From typing-label with MIT License 5 votes vote down vote up
/** Calculates the fadeout of this effect, if any. Only considers the second half of the duration. */
protected float calculateFadeout() {
    if(Float.isInfinite(duration)) return 1;

    // Calculate raw progress
    float progress = MathUtils.clamp(totalTime / duration, 0, 1);

    // If progress is before the split point, return a full factor
    if(progress < FADEOUT_SPLIT) return 1;

    // Otherwise calculate from the split point
    return Interpolation.smooth.apply(1, 0, (progress - FADEOUT_SPLIT) / (1f - FADEOUT_SPLIT));
}
 
Example 8
Source File: PreferencesManagerGDX.java    From Entitas-Java with MIT License 5 votes vote down vote up
@Override
public void load() {
    if(preferences != null) {
        APP_NAME = preferences.getString(Constants.PREFS_NAME, "TEST_GAME");
        SOUND = preferences.getBoolean(Constants.PREF_SOUND_ENABLED, true);
        MUSIC = preferences.getBoolean(Constants.PREF_MUSIC_ENABLED, true);
        VOL_SOUND = MathUtils.clamp(preferences.getFloat(Constants.PREF_VOLUME_SOUND, 0.5f),
                0.0f, 1.0f);
        VOL_MUSIC = MathUtils.clamp(preferences.getFloat(Constants.PREF_VOLUME_MUSIC, 0.5f),
                0.0f, 1.0f);
        TOUCH_PAD_ENABLED = preferences.getBoolean(Constants.PREF_TOUCHPAD_ENABLED, true);
        PROFILE_DATA_FILE = preferences.getString(Constants.PREF_PROFILE_DATA_FILE, "data/profile.game");
        INIT_PROFILE_DATA_FILE = preferences.getString(Constants.PREF_INIT_PROFILE_DATA_FILE, "data/initProfile.game");
        GAME_HEIGHT = preferences.getFloat(Constants.PREF_GAME_HEIGHT, 16.875F); // 1080 / 64 =16.875 px
        GAME_WIDTH = preferences.getFloat(Constants.PREF_GAME_WIDTH, 30F); // 1920 / 64 = 30f px
        VIRTUAL_DEVICE_HEIGHT = preferences.getInteger(Constants.PREF_VIRTUAL_DEVICE_HEIGHT, 1080); // 16.875 x 64 =1080 px
        VIRTUAL_DEVICE_WIDTH = preferences.getInteger(Constants.PREF_VIRTUAL_DEVICE_WIDTH, 1920); //  30 x 64 = 1920 px
        MAX_FPS = preferences.getInteger(Constants.PREF_MAX_FPS, 30);
        MIN_FPS = preferences.getInteger(Constants.PREF_MIN_FPS, 15);
        VELOCITY_ITERATIONS = preferences.getInteger(Constants.PREF_VELOCITY_ITERATIONS, 10); //  30 x 64 = 1920 px
        POSITION_ITERATIONS = preferences.getInteger(Constants.PREF_POSITION_ITERATIONS, 8); //  30 x 64 = 1920 px

        //Box2DLigth
        GAMMA_CORRECTION = preferences.getBoolean(Constants.PREF_GAMMA_CORRECTION, true);
        USE_DIFFUSE_LIGHT = preferences.getBoolean(Constants.PREF_USE_DIFFUSE_LIGHT, false);
        BLUR = preferences.getBoolean(Constants.PREF_BLUR, true);
        BLUR_NUM = preferences.getInteger(Constants.PREF_BLUR_NUM, 1);
        SHADOWS = preferences.getBoolean(Constants.PREF_SHADOWS, true);
        CULLING = preferences.getBoolean(Constants.PREF_CULLING, true);
       // AMBIENT_LIGHT = preferences.get(Constants.PREF_AMBIENT_LIGHT, 0.9F);

    }
}
 
Example 9
Source File: Movement.java    From gdx-proto with Apache License 2.0 5 votes vote down vote up
void limitVelocity() {
	velocity.y = MathUtils.clamp(velocity.y, -maxVerticalSpeed, maxVerticalSpeed);
	tmpv2.set(velocity.x, velocity.z);
	tmpv2.limit(maxHorizontalSpeed);
	velocity.x = tmpv2.x;
	velocity.z = tmpv2.y;
}
 
Example 10
Source File: FloatSetting.java    From Cubes with MIT License 4 votes vote down vote up
@Override
public void readJson(JsonValue json) {
  this.f = json.asFloat();
  if (hasRange) MathUtils.clamp(f, rangeStart, rangeEnd);
  onChange();
}
 
Example 11
Source File: PlayerTensiveMusic.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
@Override
public void tick () {
	if (isPaused) return;

	float tgt_vol = 0;
	// boolean isAheadByMeters = false;

	// limit to number of actual replays
	musicIndexLimit = NumTracks - 2;// MathUtils.clamp(lapManager.getReplaysCount(), 0, NumTracks - 2);
	// musicIndexLimit = NumTracks - 2;

	if (hasPlayer) {

		// assumes index 0 (player in disadvantage)
		musicIndex = 0;
		fMusicIndex = 0;

		// default interpolation speed
		float alpha_inc = 0.05f;
		float alpha_inc_next = 0.025f;
		float alpha_dec = 0.02f;

		if (!progressData.isWarmUp && progressData.hasTarget && !progressData.targetArrived) {

			// slow down interpolation speed, but bring it back when slowing down time
			alpha_inc = 0.02f / URacer.timeMultiplier;

			float v = progressData.playerDistance.get() - progressData.targetDistance.get();
			v = MathUtils.clamp(v, -ScaleMt, ScaleMt);
			v *= InvScaleMt; // normalized range
			float to_target = AMath.fixup(v);

			if (to_target >= (AheadByMt * InvScaleMt) && musicIndexLimit == NumTracks - 2) {
				// player ahead by AheadByMt meters, can play very latest track
				musicIndex = NumTracks - 1;
				fMusicIndex = musicIndex;
				musicIndexLimit = musicIndex;
			} else if (to_target > 0) {
				// player is heading the race
				musicIndex = musicIndexLimit;
				fMusicIndex = musicIndex;
			} else {
				tgt_vol = 1 - MathUtils.clamp(-to_target, 0, 1);
				fMusicIndex = tgt_vol * musicIndexLimit;
				musicIndex = (int)fMusicIndex;
				// Gdx.app.log("PlayerTensiveMusic", "to_target=" + to_target + ", tgt_vol=" + tgt_vol + ", midx=" + musicIndex);
				// Gdx.app.log("PlayerTensiveMusic", "to_target=" + to_target + ", tgt_vol=" + tgt_vol + ", midx=" + musicIndex);
				// Gdx.app.log("PlayerTensiveMusic", "fmusidx=" + fMusicIndex + ", limit=" + musicIndexLimit);
			}
		}

		// String targetString = "";
		// if (progressData.hasTarget) {
		// targetString = ", td=" + progressData.targetDistance.get();
		// }
		//
		// Gdx.app.log("PlayerTensiveMusic", "mi=" + musicIndex + ", limit=" + musicIndexLimit + ", pd="
		// + progressData.playerDistance.get() + targetString);

		// update all volume accumulators
		// float step = (1f - MinVolume) / (float)(NumTracks - 1);
		for (int i = 0; i <= NumTracks - 1; i++) {
			if (i == musicIndex && i <= musicIndexLimit) {
				float decimal = AMath.fixup(fMusicIndex - musicIndex);

				float vol_this = MathUtils.clamp((1 - decimal) * trackVolumes[i], MinVolume, 1);
				volTrack[i].set(vol_this, alpha_inc);

				int next = i + 1;
				if (next <= musicIndexLimit) {
					float vol_next = MathUtils.clamp(volOut[next] + decimal * trackVolumes[next], 0, 1);
					// Gdx.app.log("PlayerTensiveMusic", "vol_next=" + vol_next);

					volTrack[next].set(vol_next, alpha_inc_next);
				}
			} else {
				volTrack[i].set(0, alpha_dec);
			}

			// interpolate and set
			volOut[i] = volTrack[i].get() * 1f * SoundManager.MusicVolumeMul;
			setVolume(i, volOut[i]);
		}
	}
}
 
Example 12
Source File: TrackProgress.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
public void render (SpriteBatch batch, float cameraZoom) {
	// advantage/disadvantage
	float timeFactor = URacer.Game.getTimeModFactor() * 0.3f;

	// advantage if > 0, disadvantage if < 0
	float dist = MathUtils.clamp(data.playerToTarget, -1, 1);
	Color advantageColor = ColorUtils.paletteRYG(dist + 1, 1f);

	float adist = Math.abs(dist);
	float s = cameraZoom;
	if (dist < 0) {
		s += 0.5f * adist;
	}

	boolean showAdv = true;
	if (customMessage.length() == 0) {
		if (hasTarget) {
			float v = data.playerDistance.get() - data.targetDistance.get();
			lblAdvantage.setString(String.format("%.02f", v) + " m", false);
		} else {
			showAdv = false;
		}
	} else {
		lblAdvantage.setString(customMessage);
	}

	if (showAdv) {
		if (!lblAdvantageShown) {
			lblAdvantageShown = true;
			lblAdvantage.fadeIn(500);
		}
	} else if (lblAdvantageShown) {
		lblAdvantageShown = false;
		lblAdvantage.fadeOut(1000);
	}

	if (lblAdvantage.getAlpha() > 0) {
		lblAdvantage.setColor(advantageColor);
		lblAdvantage.setScale(s);
		lblAdvantage.setPosition(position.x, position.y - cameraZoom * 100 - cameraZoom * 100 * timeFactor - cameraZoom * 20
			* adist);
		lblAdvantage.render(batch);
	}

	if (data.isCurrentLapValid) {
		float scl = cameraZoom * scale * (1f + timeFactor);
		batch.setShader(shProgress);

		// set mask
		texMask.bind(1);
		Gdx.gl.glActiveTexture(GL20.GL_TEXTURE0);
		shProgress.setUniformi("u_texture1", 1);

		scl += .07f * URacer.Game.getTimeModFactor();

		// player's track progress
		playerProgress.set(data.playerProgress.get(), 0.125f);

		shProgress.setUniformf("progress", playerProgress.get());
		sprProgress.setColor(Color.WHITE);
		sprProgress.setScale(scl);
		sprProgress.setPosition(position.x - sprProgress.getWidth() / 2, position.y - sprProgress.getHeight() / 2);
		sprProgress.draw(batch, 0.5f);
		batch.flush();

		boolean isBack = (dist < 0);
		if (isBack && !flipped) {
			flipped = true;
			sprAdvantage.flip(true, false);
		} else if (!isBack && flipped) {
			flipped = false;
			sprAdvantage.flip(true, false);
		}

		// player's advantage/disadvantage
		if (hasTarget && !data.isWarmUp) {
			playerToTarget.set(Math.abs(data.playerToTarget), 0.125f);
			// Gdx.app.log("", "p2t=" + data.playerToTarget + ", my=" + playerToTarget.get());

			shProgress.setUniformf("progress", playerToTarget.get());
			sprAdvantage.setColor(advantageColor);
			sprAdvantage.setScale(scl * 1.1f);
			sprAdvantage.setPosition(position.x - sprAdvantage.getWidth() / 2, position.y - sprAdvantage.getHeight() / 2);
			sprAdvantage.draw(batch, 1);
			batch.flush();
		}

		batch.setShader(null);
	}
}
 
Example 13
Source File: PlayModeConfig.java    From beatoraja with GNU General Public License v3.0 4 votes vote down vote up
public void validate(int keys) {
    if(playconfig == null) {
        playconfig = new PlayConfig();
    }

    playconfig.validate();

    if (keyboard.keys == null) {
        keyboard.keys = new int[] { Keys.Z, Keys.S, Keys.X, Keys.D, Keys.C, Keys.F, Keys.V, Keys.SHIFT_LEFT,
                Keys.CONTROL_LEFT };
    }
    if (keyboard.keys.length != keys) {
        keyboard.keys = Arrays.copyOf(keyboard.keys, keys);
    }
    keyboard.duration = MathUtils.clamp(keyboard.duration, 0, 100);

    int index = 0;
    for (ControllerConfig c : controller) {
        if (c.keys == null) {
            c.keys = new int[] { BMKeys.BUTTON_4, BMKeys.BUTTON_7, BMKeys.BUTTON_3, BMKeys.BUTTON_8,
                    BMKeys.BUTTON_2, BMKeys.BUTTON_5, BMKeys.LEFT, BMKeys.UP, BMKeys.DOWN };
        }
        if (c.keys.length != keys) {
            int[] newkeys = new int[keys];
            Arrays.fill(newkeys, -1);
            for (int i = 0; i < c.keys.length && index < newkeys.length; i++, index++) {
                newkeys[index] = c.keys[i];
            }
            c.keys = newkeys;
        }
        c.duration = MathUtils.clamp(c.duration, 0, 100);
    }

    if (midi.keys == null) {
        midi.keys = new MidiConfig().keys;
    }
    if (midi.keys.length != keys) {
        midi.keys = Arrays.copyOf(midi.keys, keys);
    }

    // KB, コントローラー, Midiの各ボタンについて排他的処理を実施
    boolean[] exclusive = new boolean[keyboard.keys.length];
    validate0(keyboard.keys,  exclusive);
    for(int i = 0;i < controller.length;i++) {
        validate0(controller[i].keys,  exclusive);
    }

    for(int i = 0;i < midi.getKeys().length;i++) {
        if(exclusive[i]) {
            midi.getKeys()[i] = null;
        }
    }
}
 
Example 14
Source File: SinglePlayer.java    From uracer-kotd with Apache License 2.0 4 votes vote down vote up
private float getOutOfTrackFactor () {
	float oot = MathUtils.clamp(getOutOfTrackTimer().elapsed().absSeconds, 0, 0.5f) * 2;
	float s = MathUtils.clamp(playerCar.carState.currSpeedFactor * 100f, 0, 1);
	// Gdx.app.log("", "oot=" + oot + ", s=" + s);
	return 0.075f * oot * s;
}
 
Example 15
Source File: Scene2dFollowFlowFieldTest.java    From gdx-ai with Apache License 2.0 4 votes vote down vote up
@Override
public Vector2 lookup (Vector2 position) {
	int column = (int)MathUtils.clamp(position.x / resolution, 0, columns - 1);
	int row = (int)MathUtils.clamp(position.y / resolution, 0, rows - 1);
	return field[column][row];
}
 
Example 16
Source File: ScrollPane.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public float getScrollPercentY () {
	if (maxY == 0) return 0;
	return MathUtils.clamp(amountY / maxY, 0, 1);
}
 
Example 17
Source File: Voiceover.java    From jorbs-spire-mod with MIT License 4 votes vote down vote up
public void update() {
    this.duration -= Gdx.graphics.getDeltaTime();

    switch (state) {
        case INITIAL_DELAY:
            if (this.duration <= 0.0F) {
                this.state = State.DAMPENING_MASTER_VOLUME;
                this.duration = Math.max(dampeningDuration, 0.01F);
            }
            break;

        case DAMPENING_MASTER_VOLUME:
            float dampenProgress = dampeningDuration <= 0.0F ? 1.0F : MathUtils.clamp(1 - duration / dampeningDuration, 0F, 1F);
            VoiceoverMaster.MASTER_DAMPENING_FACTOR = MathUtils.lerp(1.0F, DAMPENING_FACTOR, dampenProgress);
            CardCrawlGame.music.updateVolume();

            if (this.duration <= 0.0F) {
                if (VoiceoverMaster.VOICEOVER_SUBTITLES_ENABLED) {
                    AbstractDungeon.effectList.add(new SpeechBubble(source.dialogX, source.dialogY, PLAY_DURATION, subtitle, source.isPlayer));
                }
                sfx.play(Settings.MASTER_VOLUME * VoiceoverMaster.VOICEOVER_VOLUME * VoiceoverMaster.VOICEOVER_VOLUME_MODIFIER);

                this.state = State.PLAYING_SFX;
                this.duration = PLAY_DURATION;
            }
            break;

        case PLAYING_SFX:
            if (this.duration <= 0.0F) {
                this.state = State.RESTORING_MASTER_VOLUME;
                this.duration = DAMPENING_RESTORE_DURATION;
            }
            break;

        case RESTORING_MASTER_VOLUME:
            float restoreProgress = MathUtils.clamp(1 - duration / DAMPENING_RESTORE_DURATION, 0F, 1F);
            VoiceoverMaster.MASTER_DAMPENING_FACTOR = MathUtils.lerp(DAMPENING_FACTOR, 1.0F, restoreProgress);
            CardCrawlGame.music.updateVolume();

            if (this.duration <= 0.0F) {
                VoiceoverMaster.MASTER_DAMPENING_FACTOR = 1.0F;
                this.state = State.DONE;
            }
            break;
    }
}
 
Example 18
Source File: ScrollPane.java    From riiablo with Apache License 2.0 4 votes vote down vote up
public float getVisualScrollPercentY () {
	if (maxY == 0) return 0;
	return MathUtils.clamp(visualAmountY / maxY, 0, 1);
}
 
Example 19
Source File: SceneCamera.java    From bladecoder-adventure-engine with Apache License 2.0 3 votes vote down vote up
public void getInputUnProject(Viewport viewport, Vector3 out) {

		out.set(Gdx.input.getX(), Gdx.input.getY(), 0);

		unproject(out, viewport.getScreenX(), viewport.getScreenY(), viewport.getScreenWidth(),
				viewport.getScreenHeight());

		out.x = MathUtils.clamp(out.x, 0, scrollingWidth - 1);
		out.y = MathUtils.clamp(out.y, 0, scrollingHeight - 1);
	}
 
Example 20
Source File: ConeLight.java    From box2dlights with Apache License 2.0 2 votes vote down vote up
/**
 * How big is the arc of cone
 * 
 * <p>Arc angle = coneDegree * 2, centered over direction angle
 * <p>Actual recalculations will be done only on {@link #update()} call
 * 
 */
public void setConeDegree(float coneDegree) {
	this.coneDegree = MathUtils.clamp(coneDegree, 0f, 180f);
	dirty = true;
}