當前位置: 首頁>>代碼示例>>Java>>正文


Java Vector2f.set方法代碼示例

本文整理匯總了Java中com.jme3.math.Vector2f.set方法的典型用法代碼示例。如果您正苦於以下問題:Java Vector2f.set方法的具體用法?Java Vector2f.set怎麽用?Java Vector2f.set使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在com.jme3.math.Vector2f的用法示例。


在下文中一共展示了Vector2f.set方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: updateVector

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
/**
 * Update the vector.
 *
 * @param event the event
 */
@FXThread
private void updateVector(@Nullable final KeyEvent event) {
    if (isIgnoreListener() || (event != null && event.getCode() != KeyCode.ENTER)) return;

    final FloatTextField xField = getXField();
    final float x = xField.getValue();

    final FloatTextField yField = getYField();
    final float y = yField.getValue();

    final Vector2f oldValue = getPropertyValue() == null ? Vector2f.ZERO : getPropertyValue();
    final Vector2f newValue = new Vector2f();
    newValue.set(checkResultXValue(x, y), checkResultYValue(x, y));

    changed(newValue, oldValue.clone());
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:22,代碼來源:Vector2FPropertyControl.java

示例2: getTriangleAtPoint

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
/**
 * Get the triangle that the point is on.
 * 
 * @param x coordinate in local space to the geomap
 * @param z coordinate in local space to the geomap
 * @return triangle in local space to the geomap
 */
protected Triangle getTriangleAtPoint(float x, float z) {
    Triangle[] triangles = getGridTrianglesAtPoint(x, z);
    if (triangles == null) {
        System.out.println("x,z: " + x + "," + z);
        return null;
    }
    Vector2f point = new Vector2f(x, z);
    Vector2f t1 = new Vector2f(triangles[0].get1().x, triangles[0].get1().z);
    Vector2f t2 = new Vector2f(triangles[0].get2().x, triangles[0].get2().z);
    Vector2f t3 = new Vector2f(triangles[0].get3().x, triangles[0].get3().z);

    if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) {
        return triangles[0];
    }

    t1.set(triangles[1].get1().x, triangles[1].get1().z);
    t1.set(triangles[1].get2().x, triangles[1].get2().z);
    t1.set(triangles[1].get3().x, triangles[1].get3().z);

    if (0 != FastMath.pointInsideTriangle(t1, t2, t3, point)) {
        return triangles[1];
    }

    return null;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:33,代碼來源:LODGeomap.java

示例3: parseInto

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
private void parseInto(String text, Vector2f res) throws IllegalArgumentException {
    text = text.replace('[', ' ');
    text = text.replace(']', ' ').trim();
    String[] a = text.split("\\s*(,|\\s)\\s*");

    if (a.length == 1) {
        if(text.trim().toLowerCase().equals("nan")) {
            res.set(new Vector2f(Float.NaN, Float.NaN));
            return;
        }
        float f = Float.parseFloat(text);            
        res.set(f, f);
        return;
    }

    if (a.length == 2) {
        res.set(Float.parseFloat(a[0]), Float.parseFloat(a[1]));
        return;
    }
    throw new IllegalArgumentException("String not correct");
}
 
開發者ID:jMonkeyEngine,項目名稱:sdk,代碼行數:22,代碼來源:Vector2fPropertyEditor.java

示例4: getWayPointIndexForDistance

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
/**
 * compute the index of the waypoint and the interpolation value according to a distance
 * returns a vector 2 containing the index in the x field and the interpolation value in the y field
 * @param distance the distance traveled on this path
 * @return the waypoint index and the interpolation value in a vector2
 */
private Vector2f getWayPointIndexForDistance(float distance, Vector2f store) {
    float sum = 0;
    distance = distance % spline.getTotalLength();
    int i = 0;
    for (Float len : spline.getSegmentsLength()) {
        if (sum + len >= distance) {
            store.set((float) i, (distance - sum) / len);
            return store;
        }
        sum += len;
        i++;
    }
    store.set((float) spline.getControlPoints().size() - 1, 1.0f);
    return store;
}
 
開發者ID:huliqing,項目名稱:LuoYing,代碼行數:22,代碼來源:ActorCurveMove.java

示例5: getPointPercentagePosition

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
private @NotNull Vector2f getPointPercentagePosition(@NotNull final Terrain terrain, @NotNull final Vector3f localPoint,
                                            @NotNull final Vector3f localScale, @NotNull final Vector2f result) {
    result.set(localPoint.x, -localPoint.z);

    float scale = localScale.getX();

    // already centered on Terrain's node origin (0,0)
    float scaledSize = terrain.getTerrainSize() * scale;
    result.addLocal(scaledSize / 2, scaledSize / 2); // shift the bottom left corner up to 0,0
    result.divideLocal(scaledSize); // get the location as a percentage

    return result;
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:14,代碼來源:PaintTerrainToolControl.java

示例6: getUV

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
public Vector2f getUV(int x, int y, Vector2f store, Vector2f offset, float offsetAmount, int totalSize) {
    float offsetX = offset.x + (offsetAmount * 1.0f);//stepScale.x);
    float offsetY = offset.y + (offsetAmount * 1.0f);//stepScale.z);

    store.set((((float) x) + offsetX) / (float) totalSize, // calculates percentage of texture here
            (((float) y) + offsetY) / (float) totalSize);
    return store;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:9,代碼來源:LODGeomap.java

示例7: getTex

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
public Vector2f getTex(float x, float z, Vector2f store) {
    if (x < 0 || z < 0 || x >= size || z >= size) {
        store.set(Vector2f.ZERO);
        return store;
    }
    int idx = (int) (z * size + x);
    return store.set(getMesh().getFloatBuffer(Type.TexCoord).get(idx*2),
                     getMesh().getFloatBuffer(Type.TexCoord).get(idx*2+1) );
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:10,代碼來源:TerrainPatch.java

示例8: createLumShader

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
private Material createLumShader(int srcW, int srcH, int bufW, int bufH, int mode,
                            int iters, Texture tex){
    Material mat = new Material(manager, "Common/MatDefs/Hdr/LogLum.j3md");
    
    Vector2f blockSize = new Vector2f(1f / bufW, 1f / bufH);
    Vector2f pixelSize = new Vector2f(1f / srcW, 1f / srcH);
    Vector2f blocks = new Vector2f();
    float numPixels = Float.POSITIVE_INFINITY;
    if (iters != -1){
        do {
            pixelSize.multLocal(2);
            blocks.set(blockSize.x / pixelSize.x,
                       blockSize.y / pixelSize.y);
            numPixels = blocks.x * blocks.y;
        } while (numPixels > iters);
    }else{
        blocks.set(blockSize.x / pixelSize.x,
                   blockSize.y / pixelSize.y);
        numPixels = blocks.x * blocks.y;
    }
    System.out.println(numPixels);

    mat.setBoolean("Blocks", true);
    if (mode == LUMMODE_ENCODE_LUM)
        mat.setBoolean("EncodeLum", true);
    else if (mode == LUMMODE_DECODE_LUM)
        mat.setBoolean("DecodeLum", true);

    mat.setTexture("Texture", tex);
    mat.setVector2("BlockSize", blockSize);
    mat.setVector2("PixelSize", pixelSize);
    mat.setFloat("NumPixels", numPixels);

    return mat;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:36,代碼來源:HDRRenderer.java

示例9: rotatedBoundsLocal

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
public static Vector2f rotatedBoundsLocal(Vector2f rect, float rad) {
	float s = FastMath.sin(rad);
	float c = FastMath.cos(rad);
	float rx = rect.y * FastMath.abs(s) + rect.x * FastMath.abs(c);
	float ry = rect.y * FastMath.abs(c) + rect.x * FastMath.abs(s);
	rect.set(rx, ry);
	return rect;
}
 
開發者ID:rockfireredmoon,項目名稱:icetone,代碼行數:9,代碼來源:MathUtil.java

示例10: rot

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
public Vector2f rot(Vector2f p, float angle) {
	cos = FastMath.cos(angle * FastMath.DEG_TO_RAD);
	sin = FastMath.sin(angle * FastMath.DEG_TO_RAD);
	x = p.x * cos - p.y * sin;
	y = p.x * sin + p.y * cos;
	return p.set(x, y);
}
 
開發者ID:rockfireredmoon,項目名稱:icetone,代碼行數:8,代碼來源:AnimElementMesh.java

示例11: modifyHeight

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
/**
 * Modify height of terrain points.
 *
 * @param contactPoint the contact point.
 */
private void modifyHeight(@NotNull final Vector3f contactPoint) {

    final LocalObjects local = LocalObjects.get();
    final Node terrainNode = (Node) notNull(getEditedModel());

    final Vector3f worldTranslation = terrainNode.getWorldTranslation();
    final Vector3f localScale = terrainNode.getLocalScale();
    final Vector3f localPoint = contactPoint.subtract(worldTranslation, local.nextVector());
    final Vector2f terrainLoc = local.nextVector2f();
    final Vector2f effectPoint = local.nextVector2f();

    final Terrain terrain = (Terrain) terrainNode;
    final Geometry brush = getBrush();

    final float brushSize = getBrushSize();
    final int twoBrushSize = (int) (brushSize * 2);

    final Basis fractalFilter = createFractalGenerator();
    final FloatBuffer buffer = fractalFilter.getBuffer(terrainLoc.getX(), terrainLoc.getY(), 0, twoBrushSize);

    final int radiusStepsX = (int) (brushSize / localScale.getX());
    final int radiusStepsZ = (int) (brushSize / localScale.getY());

    final float xStepAmount = localScale.getX();
    final float zStepAmount = localScale.getZ();

    final List<Vector2f> locs = new ArrayList<>();
    final List<Float> heights = new ArrayList<>();

    for (int z = -radiusStepsZ, yfb = 0; z < radiusStepsZ; z++, yfb++) {
        for (int x = -radiusStepsX, xfb = 0; x < radiusStepsX; x++, xfb++) {

            final float locX = localPoint.getX() + (x * xStepAmount);
            final float locZ = localPoint.getZ() + (z * zStepAmount);

            effectPoint.set(locX - localPoint.getX(), locZ - localPoint.getZ());

            if (!isContains(brush, effectPoint.getX(), effectPoint.getX())) {
                continue;
            }

            final float height = buffer.get(yfb * twoBrushSize + xfb);

            terrainLoc.set(locX, locZ);

            final float currentHeight = terrain.getHeightmapHeight(terrainLoc) * localScale.getY();
            // see if it is in the radius of the tool
            final float newHeight = calculateHeight(brushSize, height, effectPoint);

            locs.add(terrainLoc.clone());
            heights.add(currentHeight + newHeight);
        }
    }

    locs.forEach(this::change);

    // do the actual height adjustment
    terrain.setHeight(locs, heights);
    terrainNode.updateModelBound(); // or else we won't collide with it where we just edited
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:66,代碼來源:RoughTerrainToolControl.java

示例12: modifyHeight

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
/**
 * Modify height of terrain points.
 *
 * @param editingInput the type of input.
 * @param contactPoint the contact point.
 */
private void modifyHeight(@NotNull final EditingInput editingInput, @NotNull final Vector3f contactPoint) {

    final LocalObjects local = LocalObjects.get();
    final Node terrainNode = (Node) notNull(getEditedModel());

    final Vector3f worldTranslation = terrainNode.getWorldTranslation();
    final Vector3f localScale = terrainNode.getLocalScale();
    final Vector3f localPoint = contactPoint.subtract(worldTranslation, local.nextVector());
    final Vector2f terrainLoc = local.nextVector2f();
    final Vector2f effectPoint = local.nextVector2f();

    final Terrain terrain = (Terrain) terrainNode;
    final Geometry brush = getBrush();

    final float brushSize = getBrushSize();
    final float brushPower = editingInput == EditingInput.MOUSE_PRIMARY ? getBrushPower() : getBrushPower() * -1F;

    final int radiusStepsX = (int) (brushSize / localScale.getX());
    final int radiusStepsZ = (int) (brushSize / localScale.getY());

    final float xStepAmount = localScale.getX();
    final float zStepAmount = localScale.getZ();

    final List<Vector2f> locs = new ArrayList<>();
    final List<Float> heights = new ArrayList<>();

    for (int z = -radiusStepsZ; z < radiusStepsZ; z++) {
        for (int x = -radiusStepsX; x < radiusStepsX; x++) {

            float locX = localPoint.getX() + (x * xStepAmount);
            float locZ = localPoint.getZ() + (z * zStepAmount);

            effectPoint.set(locX - localPoint.getX(), locZ - localPoint.getZ());

            if (!isContains(brush, effectPoint.getX(), effectPoint.getY())) {
                continue;
            }

            terrainLoc.set(locX, locZ);

            final float currentHeight = terrain.getHeightmapHeight(terrainLoc) * localScale.getY();
            // adjust height based on radius of the tool
            final float newHeight = calculateHeight(brushSize, brushPower, effectPoint.getX(), effectPoint.getY());

            // increase the height
            locs.add(terrainLoc.clone());
            heights.add(currentHeight + newHeight);
        }
    }

    locs.forEach(this::change);

    // do the actual height adjustment
    terrain.setHeight(locs, heights);
    terrainNode.updateModelBound(); // or else we won't collide with it where we just edited
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:63,代碼來源:RaiseLowerTerrainToolControl.java

示例13: doPaintAction

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
/**
 * Goes through each pixel in the image. At each pixel it looks to see if the UV mouse coordinate is within the
 * of the brush. If it is in the brush radius, it gets the existing color from that pixel so it can add/subtract to/from it.
 * Essentially it does a radius check and adds in a fade value. It does this to the color value returned by the
 * first pixel color query.
 * Next it sets the color of that pixel. If it was within the radius, the color will change. If it was outside
 * the radius, then nothing will change, the color will be the same; but it will set it nonetheless. Not efficient.
 * <p>
 * If the mouse is being dragged with the button down, then the dragged value should be set to true. This will reduce
 * the intensity of the brush to 10% of what it should be per spray. Otherwise it goes to 100% opacity within a few pixels.
 * This makes it work a little more realistically.
 *
 * @param colorFunction the color function.
 * @param image         to manipulate
 * @param uv            the world x,z coordinate
 * @param radius        in percentage so it can be translated to the image dimensions
 * @param erase         true if the tool should remove the paint instead of add it
 * @param fadeFalloff   the percentage of the radius when the paint begins to start fading
 */
private void doPaintAction(@NotNull final ObjectFloatObjectConsumer<ColorRGBA, Boolean> colorFunction,
                           @NotNull final Image image, @NotNull final Vector2f uv, @NotNull final Vector2f temp,
                           @NotNull final ColorRGBA color, final float radius, final boolean erase,
                           final float fadeFalloff) {

    final ByteBuffer buffer = image.getData(0);

    final int width = image.getWidth();
    final float height = image.getHeight();

    // convert percents to pixels to limit how much we iterate
    final int minX = (int) Math.max(0, (uv.getX() * width - radius * width));
    final int maxX = (int) Math.min(width, (uv.getX() * width + radius * width));
    final int minY = (int) Math.max(0, (uv.getY() * height - radius * height));
    final int maxY = (int) Math.min(height, (uv.getY() * height + radius * height));

    final float radiusSquared = radius * radius;

    // go through each pixel, in the radius of the tool, in the image
    for (int y = minY; y < maxY; y++) {
        for (int x = minX; x < maxX; x++) {

            // gets the position in percentage so it can compare with the mouse UV coordinate
            temp.set((float) x / width, (float) y / height);

            float dist = temp.distanceSquared(uv);

            // if the pixel is within the distance of the radius, set a color (distance times intensity)
            if (dist < radiusSquared) {

                final int position = (y * width + x) * 4;
                if (position > buffer.capacity() - 1 || position < 0) {
                    continue;
                }

                // gets the color at that location (false means don't write to the buffer)
                manipulatePixel(image, buffer, color, position, false);

                // calculate the fade falloff intensity
                final float intensity = (1.0f - (dist / radiusSquared)) * fadeFalloff;

                colorFunction.accept(color, intensity, erase);
                color.clamp();

                change(position, color);

                // set the new color
                manipulatePixel(image, buffer, color, position, true);
            }
        }
    }

    image.getData(0).rewind();
}
 
開發者ID:JavaSaBr,項目名稱:jmonkeybuilder,代碼行數:74,代碼來源:PaintTerrainToolControl.java

示例14: getUV

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
public Vector2f getUV(int x, int y, Vector2f store){
    store.set( (float)x / (float)getWidth(),
               (float)y / (float)getHeight() );
    return store;
}
 
開發者ID:mleoking,項目名稱:PhET,代碼行數:6,代碼來源:AbstractGeomap.java

示例15: onLayout

import com.jme3.math.Vector2f; //導入方法依賴的package包/類
@Override
protected void onLayout(Button parent) {
	final String text1 = parent.getText();
	Vector4f margin = parent.getMargin();
	Vector4f textPadding = parent.getAllPadding();
	Vector2f dim = parent.getDimensions().subtract(margin.x  + margin.y, margin.z  + margin.w);
	Vector2f ip = parent.getButtonIcon().calcPreferredSize();
	if (parent.getButtonIcon().getElementTexture() != null || !Vector2f.ZERO.equals(ip)) {
		Vector2f ps = calcTextSize(parent, parent.getWidth() - parent.getTotalPadding().x);
		if (ps == null)
			ps = Vector2f.ZERO;
		Vector2f sz = ip.clone();
		if (Vector2f.ZERO.equals(ip)) {
			// Element is as big as we want it
			float sc = Math.min(ps.x, ps.y);
			sz.x = sc / 2f;
			sz.y = sc / 2f;
		}

		Vector2f pos = new Vector2f();

		float cx = ((parent.getWidth() - textPadding.x - textPadding.y) / 2f) - (sz.x / 2f) + textPadding.x;
		if (text1 == null || text1.equals("")) {
			pos.set(cx, (parent.getHeight() / 2f) - (sz.y / 2f));
		} else {
			switch (parent.getButtonIconAlign()) {
			case Left:
				pos.set(textPadding.x, (parent.getHeight() / 2f) - (sz.y / 2f));
				break;
			case Right:
				pos.set(parent.getWidth() - sz.x - textPadding.y, (parent.getHeight() / 2) - (sz.y / 2));
				break;
			default:
				switch (parent.getTextVAlign()) {
				case Top:
					pos.set(cx, parent.getHeight() - sz.y - textPadding.w);
					break;
				case Bottom:
					pos.set(cx, textPadding.z);
					break;
				default:
					pos.set(cx, (parent.getHeight() / 2f) - (sz.y / 2f));
					break;
				}
				break;
			}
		}
		parent.getButtonIcon().setBounds(pos.x, pos.y, sz.x, sz.y);
	}
	parent.getOverlay().setBounds(margin.x, margin.z, dim.x, dim.y);

}
 
開發者ID:rockfireredmoon,項目名稱:icetone,代碼行數:53,代碼來源:Button.java


注:本文中的com.jme3.math.Vector2f.set方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。