本文整理匯總了Java中com.jme3.math.Vector2f類的典型用法代碼示例。如果您正苦於以下問題:Java Vector2f類的具體用法?Java Vector2f怎麽用?Java Vector2f使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
Vector2f類屬於com.jme3.math包,在下文中一共展示了Vector2f類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getClicked
import com.jme3.math.Vector2f; //導入依賴的package包/類
private CollisionResult getClicked() {
CollisionResults results = new CollisionResults();
Vector2f click2d = inputManager.getCursorPosition();
Vector3f click3d = cam.getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 0f).clone();
Vector3f dir = cam.getWorldCoordinates(
new Vector2f(click2d.x, click2d.y), 1f).subtractLocal(click3d).normalizeLocal();
Ray ray = new Ray(click3d, dir);
rootNode.collideWith(ray, results);
if (results.size() > 0)
return results.getClosestCollision();
else
return null;
}
示例2: process_slice
import com.jme3.math.Vector2f; //導入依賴的package包/類
public void process_slice(Texture tx, Texel ir, int mipmap, int slice, Map<String,String> options, DDS_HEADER header, DDS_BODY body) throws Exception{
String gen_mm=options.get("gen-mipmaps");
if(gen_mm==null)gen_mm="false";
boolean gen_mipmaps=!tx.getImage().hasMipmaps()&&gen_mm.equals("true");
if(mipmap==0&&gen_mipmaps){
int n=numMipMaps(new Vector2f(tx.getImage().getWidth(),tx.getImage().getHeight()))-1/*first mipmap is the image*/;
Texel mipmaps[]=ir.getMipMap(n,false);
super.process_slice(tx,ir,mipmap,slice,options,header,body);
for(int i=0;i<n;i++){
Texel m=mipmaps[i];
super.process_slice(tx,m,i+1,slice,options,header,body);
}
}else{
super.process_slice(tx,ir,mipmap,slice,options,header,body);
}
}
示例3: fromImageRaster
import com.jme3.math.Vector2f; //導入依賴的package包/類
public static Texel fromImageRaster(ImageRaster ir, Vector2f from, Vector2f to) {
Vector4f pixels[][]=new Vector4f[(int)(to.x-from.x)][(int)(to.y-from.y)];
for(int y=(int)from.y;y<to.y;y++){
for(int x=(int)from.x;x<to.x;x++){
int xl=(int)(x-from.x);
int yl=(int)(y-from.y);
Vector4f c;
if(x>=ir.getWidth()||y>=ir.getHeight()||x<0||y<0){
LOGGER.warn("Invalid coordinates x{} y{} for image w{} h{}. Use padding color.",x,y,ir.getWidth(),ir.getHeight());
c=PADDINGPX_COLOR;
}else{
c=ir.getPixel(x,y).toVector4f();
}
pixels[xl][yl]=c;
}
}
Texel tx=new Texel(PixelFormat.FLOAT_NORMALIZED_RGBA,pixels);
tx.AREA=new Vector2f[]{from,to
};
return tx;
}
示例4: fromTexel
import com.jme3.math.Vector2f; //導入依賴的package包/類
public static Texel fromTexel(PixelFormat dest_format, Texel tx, Vector2f from, Vector2f to) {
Vector4f pixels[][]=new Vector4f[(int)(to.x-from.x)][(int)(to.y-from.y)];
for(int y=(int)from.y;y<to.y;y++){
for(int x=(int)from.x;x<to.x;x++){
int xl=(int)(x-from.x);
int yl=(int)(y-from.y);
Vector4f c;
if(x>=tx.getWidth()||y>=tx.getHeight()||x<0||y<0){
LOGGER.warn("Invalid coordinates x{} y{} for texel w{} h{}. Use padding color.",x,y,tx.getWidth(),tx.getHeight());
c=PADDINGPX_COLOR;
}else{
c=tx.get(dest_format,x,y);
}
pixels[xl][yl]=c;
}
}
Texel tnx=new Texel(PixelFormat.FLOAT_NORMALIZED_RGBA,pixels);
tnx.AREA=new Vector2f[]{from,to
};
return tnx;
}
示例5: 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());
}
示例6: change
import com.jme3.math.Vector2f; //導入依賴的package包/類
/**
* Notify about wanting to change height of a point.
*
* @param point the point.
*/
protected void change(@NotNull final Vector2f point) {
final Terrain terrain = (Terrain) notNull(copiedTerrain);
final Node terrainNode = (Node) notNull(getEditedModel());
final Vector3f scale = terrainNode.getWorldScale();
final int halfSize = terrain.getTerrainSize() / 2;
final int x = Math.round((point.x / scale.x) + halfSize);
final int z = Math.round((point.y / scale.z) + halfSize);
final HeightPoint heightPoint = new HeightPoint(point.getX(), point.getY(), x, z);
final ObjectDictionary<HeightPoint, Float> originalHeight = getOriginalHeight();
if(originalHeight.containsKey(heightPoint)) return;
final float height = terrain.getHeightmapHeight(point);
originalHeight.put(heightPoint, height);
}
示例7: getAngle
import com.jme3.math.Vector2f; //導入依賴的package包/類
/**
* Get the angle between these points.
*
* @param center the center.
* @param first the first point.
* @param second the second point.
* @return the angle between these points.
*/
@FromAnyThread
public static float getAngle(@NotNull final Vector2f center, @NotNull final Vector2f first,
@NotNull final Vector2f second) {
final float x = center.getX();
final float y = center.getY();
final float ax = first.getX() - x;
final float ay = first.getY() - y;
final float bx = second.getX() - x;
final float by = second.getY() - y;
final float delta = (float) ((ax * bx + ay * by) / Math.sqrt((ax * ax + ay * ay) * (bx * bx + by * by)));
if (delta > 1.0) {
return 0.0F;
} else if (delta < -1.0) {
return 180.0F;
}
return (float) toDegrees(acos(delta));
}
示例8: TableRow
import com.jme3.math.Vector2f; //導入依賴的package包/類
public TableRow(BaseScreen screen, Table table, Object value) {
super(screen, null, Vector2f.ZERO, null);
layoutManager = new RowLayout();
this.value = value;
this.table = table;
setMouseFocusable(true);
setIgnoreMouseButtons(false);
setIgnoreTouch(false);
addClippingLayer(table.viewPortClipLayer, null);
addMouseButtonListener(evt -> {
if ((evt.isLeft() || (table.selectOnRightClick && evt.isRight())) && evt.isPressed())
onMouseSelect(evt);
});
}
示例9: addWindow
import com.jme3.math.Vector2f; //導入依賴的package包/類
protected void addWindow(Frame window) {
if (windows.contains(window)) {
LOG.warning(String.format("Window %s is already managed.", window));
} else {
windows.add(window);
/*
* TODO when element position becomes a Position object, use that to
* determine if position manually
*/
if (window.getPosition().equals(Vector2f.ZERO)) {
if (mode == Mode.STEP) {
window.setPosition(next);
float p = window.getDragBar().calcPreferredSize().y;
next.x += p;
next.y += p;
} else if (mode == Mode.CENTRE) {
window.centerToParent();
}
}
}
}
示例10: onLayout
import com.jme3.math.Vector2f; //導入依賴的package包/類
@Override
protected void onLayout(ElementContainer<?,?> parent) {
for (BaseElement el : parent.getElements()) {
float cx = parent.getWidth() / 2f;
float cy = parent.getHeight() / 2f;
Vector2f elpref = el.calcPreferredSize();
RadialLayoutInfo con = constraints.get(el);
String layoutData = el.getLayoutData();
if(layoutData != null && layoutData.length() > 0) {
con = parseConstraints(layoutData);
}
float inset = this.inset;
if (con != null) {
if(con.getInset() != Float.MIN_VALUE)
inset = con.getInset();
cx += FastMath.sin(con.getAngle()) * (cx - inset);
cy -= FastMath.cos(con.getAngle()) * (cy - inset);
el.setBounds(Math.round(cx - (elpref.x / 2f)), Math.round(cy - (elpref.y / 2f)), elpref.x, elpref.y);
}
}
}
示例11: AbstractMeshElement
import com.jme3.math.Vector2f; //導入依賴的package包/類
public AbstractMeshElement(BaseScreen screen, Vector2f position, Size dimension) {
super(screen, null, position, dimension, Vector4f.ZERO, null);
setIgnoreMouse(true);
meshMaterial = new Material(screen.getApplication().getAssetManager(), "icetone/shaders/Unshaded.j3md");
meshMaterial.setVector2("OffsetAlphaTexCoord", new Vector2f(0, 0));
meshMaterial.setFloat("GlobalAlpha", screen.getGlobalAlpha());
meshMaterial.getAdditionalRenderState().setBlendMode(RenderState.BlendMode.Alpha);
meshMaterial.getAdditionalRenderState().setFaceCullMode(RenderState.FaceCullMode.Back);
setLayoutManager(new DefaultLayout() {
@Override
protected void onCalcClip(ElementContainer<?,?> container) {
super.onCalcClip(container);
if (!clippingLayers.isEmpty()) {
meshMaterial.setVector4("Clipping", getClippingBounds());
meshMaterial.setBoolean("UseClipping", true);
} else {
meshMaterial.setBoolean("UseClipping", false);
}
}
});
}
示例12: finishDrop
import com.jme3.math.Vector2f; //導入依賴的package包/類
private void finishDrop(BaseElement dropEl, boolean events) {
Vector2f absDropLoc = getAbsolute();
handleSuccess(dropEl);
if (useLockToDropElementEffect) {
animating = true;
Vector2f dest = absDropLoc.subtract(getParentContainer().getAbsolute());
screen.getEffectManager()
.applyEffect(new EffectList(new SlideFromEffect(.15f, dest).setElement(this), new RunEffect(() -> {
animating = false;
handleSuccess(dropEl);
cleanUpDrop();
if (dragSupport != null && events)
dragSupport.fireEvent(new DragEvent<BaseElement>(DragElement.this, DragEventType.complete));
})));
return;
}
cleanUpDrop();
if (dragSupport != null && events)
dragSupport.fireEvent(new DragEvent<BaseElement>(this, DragEventType.complete));
}
示例13: scaleTextureCoordinates
import com.jme3.math.Vector2f; //導入依賴的package包/類
/**
* Scales the texture coordinate buffer on this mesh by the given
* scale factor.
* <p>
* Note that values above 1 will cause the
* texture to tile, while values below 1 will cause the texture
* to stretch.
* </p>
*
* @param scaleFactor The scale factor to scale by. Every texture
* coordinate is multiplied by this vector to get the result.
*
* @throws IllegalStateException If there's no texture coordinate
* buffer on the mesh
* @throws UnsupportedOperationException If the texture coordinate
* buffer is not in 2D float format.
*/
public void scaleTextureCoordinates(Vector2f scaleFactor){
VertexBuffer tc = getBuffer(Type.TexCoord);
if (tc == null)
throw new IllegalStateException("The mesh has no texture coordinates");
if (tc.getFormat() != VertexBuffer.Format.Float)
throw new UnsupportedOperationException("Only float texture coord format is supported");
if (tc.getNumComponents() != 2)
throw new UnsupportedOperationException("Only 2D texture coords are supported");
FloatBuffer fb = (FloatBuffer) tc.getData();
fb.clear();
for (int i = 0; i < fb.capacity() / 2; i++){
float x = fb.get();
float y = fb.get();
fb.position(fb.position()-2);
x *= scaleFactor.getX();
y *= scaleFactor.getY();
fb.put(x).put(y);
}
fb.clear();
tc.updateData(fb);
}
示例14: calcMaximumSize
import com.jme3.math.Vector2f; //導入依賴的package包/類
@Override
protected Vector2f calcMaximumSize(ElementContainer<?,?> target) {
Iterator<BaseElement> el = target.getElements().iterator();
double y = 0;
double x = 0;
for (int i = 0; el.hasNext() && i < h; i++) {
float my = 0;
float mx = 0;
for (int j = 0; el.hasNext() && j < w; j++) {
Vector2f thisSize = el.next().calcMaximumSize();
mx += thisSize.x;
my = Math.max(my, thisSize.y);
}
y += my;
x = Math.max(x, mx);
}
Vector2f pad = target.getTotalPadding();
y += pad.y;
x += pad.x;
return new Vector2f((float) Math.min(Float.MAX_VALUE, x), (float) Math.min(Float.MAX_VALUE, y));
}
示例15: createSpeechBubble
import com.jme3.math.Vector2f; //導入依賴的package包/類
private Element createSpeechBubble(String text, final ChannelType channel) {
Element el = new Element(screen, UIDUtil.getUID(), Vector2f.ZERO,
screen.getStyle("SpeechBubble").getVector2f("defaultSize"),
screen.getStyle("SpeechBubble").getVector4f("resizeBorders"),
screen.getStyle("SpeechBubble").getString("defaultImg")) {
{
LUtil.removeEffects(this);
populateEffects("SpeechBubble");
}
};
el.setTextWrap(LineWrapMode.Word);
el.setTextAlign(BitmapFont.Align.Center);
el.setTextVAlign(BitmapFont.VAlign.Center);
el.setFont(screen.getStyle("Font").getString(screen.getStyle("SpeechBubble").getString("fontName")));
el.setFontSize(screen.getStyle("SpeechBubble").getFloat("fontSize"));
el.setClipPadding(screen.getStyle("SpeechBubble").getFloat("clipPadding"));
el.setFontColor(UIUtil.fromColorString(
Config.get().node(Config.CHAT_CHANNELS).node(channel.name()).get("color", Icelib.toHexString(channel.getColor()))));
el.setText(text);
return el;
}