当前位置: 首页>>代码示例>>Java>>正文


Java Vector3f.subtract方法代码示例

本文整理汇总了Java中com.jme3.math.Vector3f.subtract方法的典型用法代码示例。如果您正苦于以下问题:Java Vector3f.subtract方法的具体用法?Java Vector3f.subtract怎么用?Java Vector3f.subtract使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.jme3.math.Vector3f的用法示例。


在下文中一共展示了Vector3f.subtract方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: barycentricCoords

import com.jme3.math.Vector3f; //导入方法依赖的package包/类
protected Vector3f barycentricCoords(Vector3f pA, Vector3f pB, Vector3f pC, Vector3f point) {
	Vector3f v0=pB.subtract(pA);
	Vector3f v1=pC.subtract(pA);
	Vector3f v2=point.subtract(pA);
	float d00=v0.dot(v0);
	float d01=v0.dot(v1);
	float d11=v1.dot(v1);
	float d20=v2.dot(v0);
	float d21=v2.dot(v1);
	float invDenom=1.0f/(d00*d11-d01*d01);
	float v=(d11*d20-d01*d21)*invDenom;
	float w=(d00*d21-d01*d20)*invDenom;
	float u=1.0f-v-w;
	if(u<0) return new Vector3f(-1.0f,-1.0f,-1.0f);
	return new Vector3f(u,v,w);
}
 
开发者ID:riccardobl,项目名称:JMELink-SP,代码行数:17,代码来源:Triangle.java

示例2: barycentric

import com.jme3.math.Vector3f; //导入方法依赖的package包/类
private static float[] barycentric(Vector3f p, Vector3f a, Vector3f b, Vector3f c )
{
    Vector3f v0 = b.subtract( a ),
    	 	 v1 = c.subtract( a ),
    		 v2 = p.subtract( a );
    
    float d00 = v0.dot(v0);
    float d01 = v0.dot(v1);
    float d11 = v1.dot(v1);
    float d20 = v2.dot(v0);
    float d21 = v2.dot(v1);
    
    float denom = d00 * d11 - d01 * d01;
    
    float v = (d11 * d20 - d01 * d21) / denom,
    	  w = (d00 * d21 - d01 * d20) / denom,
          u = 1.0f - v - w;
    
    return new float[] {u, v, w};
}
 
开发者ID:twak,项目名称:chordatlas,代码行数:21,代码来源:SkelFootprint.java

示例3: dragging

import com.jme3.math.Vector3f; //导入方法依赖的package包/类
@Override
	public void dragging(Vector2f screen) {
		
		Vector3f newPt = toWorld ( screen );
		Vector3f delta = newPt.subtract(dragStart);
		
		target.setLocalTranslation( target.getLocalTranslation().add(delta) );
//		target.getParent().setLocalTranslation( new Vector3f() );//.getLocalTranslation().add(delta) );
//		target.updateGeometricState();
		
//		getParent().setLocalTranslation( getParent().getLocalTranslation().add(delta) );
		updateScale();
		dragStart = newPt;
		
	}
 
开发者ID:twak,项目名称:chordatlas,代码行数:16,代码来源:MoveHandle.java

示例4: buildFrame

import com.jme3.math.Vector3f; //导入方法依赖的package包/类
private Matrix4d buildFrame( Vector3f[] locs ) {
		
		Vector3f dir0 = new Vector3f(locs[1]);
		dir0 = dir0.subtract(locs[0]);
		dir0.y = 0;
//		dir.normalize();
		
		Vector3f dir1 = new Vector3f(0,dir0.length(),0);
		Vector3f dir2 = new Vector3f(-dir0.z, 0, dir0.x);
		
		Matrix4d out = new Matrix4d();
		out.setRow( 0, toArray( dir2 ));
		out.setRow( 1, toArray( dir1 ));
		out.setRow( 2, toArray( dir0 ));
		
		out.m03 = locs[0].x;
		out.m13 = 0;
		out.m23 = locs[0].z;
		out.m33 = 1;

		if (false)
		{
			Point3d a = new Point3d (0,0,0);
			Point3d b = new Point3d (0,0,1);
			
			out.transform( a );
			out.transform( b );
			
			System.out.println( a + " >>><<< " + b );
			System.out.println( locs[0] + " <<<>>> " + locs[1] );
		}
		
		return out;
	}
 
开发者ID:twak,项目名称:chordatlas,代码行数:35,代码来源:AlignTool.java

示例5: paintTexture

import com.jme3.math.Vector3f; //导入方法依赖的package包/类
/**
 * Paint texture.
 *
 * @param editingInput the editing input.
 * @param contactPoint the contact point.
 */
private void paintTexture(@NotNull final EditingInput editingInput, @NotNull final Vector3f contactPoint) {

    final Texture alphaTexture = getAlphaTexture();
    if (alphaTexture == null) return;

    final LocalObjects local = LocalObjects.get();
    final Spatial terrainNode = notNull(getEditedModel());
    final Terrain terrain = (Terrain) terrainNode;
    final Image image = alphaTexture.getImage();

    final Vector3f worldTranslation = terrainNode.getWorldTranslation();
    final Vector3f localPoint = contactPoint.subtract(worldTranslation, local.nextVector());
    final Vector3f localScale = terrainNode.getLocalScale();
    final Vector2f uv = getPointPercentagePosition(terrain, localPoint, localScale, local.nextVector2f());
    final Vector2f temp = local.nextVector2f();
    final ColorRGBA color = local.nextColor();

    final int layer = getLayer();

    // get the radius of the brush in pixel-percent
    float brushSize = getBrushSize() / (terrain.getTerrainSize() * localScale.getX());
    float brushPower = getBrushPower();

    if (editingInput == EditingInput.MOUSE_SECONDARY) {
        brushPower *= -1;
    }

    // selectedTextureIndex/4 is an int floor, do not simplify the equation
    final ObjectFloatObjectConsumer<ColorRGBA, Boolean> colorFunction = COLOR_FUNCTIONS[layer - ((layer / 4) * 4)];

    doPaintAction(colorFunction, image, uv, temp, color, brushSize, false, brushPower);

    image.setUpdateNeeded();
}
 
开发者ID:JavaSaBr,项目名称:jmonkeybuilder,代码行数:41,代码来源:PaintTerrainToolControl.java

示例6: modifyHeight

import com.jme3.math.Vector3f; //导入方法依赖的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

示例7: modifyHeight

import com.jme3.math.Vector3f; //导入方法依赖的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


注:本文中的com.jme3.math.Vector3f.subtract方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。