public void getPlaneEquation(Vector4f plane, int i) { Vector3f halfExtents = getHalfExtentsWithoutMargin(Stack.alloc(Vector3f.class)); switch (i) { case 0: plane.set(1f, 0f, 0f, -halfExtents.x); break; case 1: plane.set(-1f, 0f, 0f, -halfExtents.x); break; case 2: plane.set(0f, 1f, 0f, -halfExtents.y); break; case 3: plane.set(0f, -1f, 0f, -halfExtents.y); break; case 4: plane.set(0f, 0f, 1f, -halfExtents.z); break; case 5: plane.set(0f, 0f, -1f, -halfExtents.z); break; default: assert (false); } }
public static void get_plane_equation_transformed(StaticPlaneShape shape, Transform trans, Vector4f equation) { get_plane_equation(shape, equation); Vector3f tmp = Stack.alloc(Vector3f.class); trans.basis.getRow(0, tmp); float x = VectorUtil.dot3(tmp, equation); trans.basis.getRow(1, tmp); float y = VectorUtil.dot3(tmp, equation); trans.basis.getRow(2, tmp); float z = VectorUtil.dot3(tmp, equation); float w = VectorUtil.dot3(trans.origin, equation) + equation.w; equation.set(x, y, z, w); }
private static BakedQuad rescaleQuad(BakedQuad quad, Matrix4f transform, int tintDelta) { final int delta = quad.getFormat().getIntegerSize(); final int[] inputVertexData = quad.getVertexData(); final int[] outputVertexData = Arrays.copyOf(inputVertexData, inputVertexData.length); int elementOffset = 0; for (int i = 0; i < 4; i++) { float x = Float.intBitsToFloat(inputVertexData[elementOffset + 0]); float y = Float.intBitsToFloat(inputVertexData[elementOffset + 1]); float z = Float.intBitsToFloat(inputVertexData[elementOffset + 2]); final Vector4f v = new Vector4f(x, y, z, 1); transform.transform(v); outputVertexData[elementOffset + 0] = Float.floatToIntBits(v.x); outputVertexData[elementOffset + 1] = Float.floatToIntBits(v.y); outputVertexData[elementOffset + 2] = Float.floatToIntBits(v.z); elementOffset += delta; } final int tintIndex = quad.hasTintIndex()? quad.getTintIndex() + tintDelta : -1; return new BakedQuad(outputVertexData, tintIndex, quad.getFace(), quad.getSprite(), quad.shouldApplyDiffuseLighting(), quad.getFormat()); }
private List<Brush> brus() throws IOException { chunk("BRUS"); List<Brush> ret = new ArrayList<Brush>(); int n_texs = buf.getInt(); while(buf.hasRemaining()) { String name = readString(); Vector4f color = new Vector4f(buf.getFloat(), buf.getFloat(), buf.getFloat(), buf.getFloat()); float shininess = buf.getFloat(); int blend = buf.getInt(); int fx = buf.getInt(); List<Texture> textures = new ArrayList<Texture>(); for(int i = 0; i < n_texs; i++) textures.add(getTexture(buf.getInt())); ret.add(new Brush(name, color, shininess, blend, fx, textures)); } dump("BRUS([" + Joiner.on(", ").join(ret) + "])"); popLimit(); this.brushes.addAll(ret); return ret; }
public static int maxAxis4(Vector4f v) { int maxIndex = -1; float maxVal = -1e30f; if (v.x > maxVal) { maxIndex = 0; maxVal = v.x; } if (v.y > maxVal) { maxIndex = 1; maxVal = v.y; } if (v.z > maxVal) { maxIndex = 2; maxVal = v.z; } if (v.w > maxVal) { maxIndex = 3; maxVal = v.w; } return maxIndex; }
public void buildTriPlane(Vector4f plane) { Vector3f tmp1 = Stack.alloc(Vector3f.class); Vector3f tmp2 = Stack.alloc(Vector3f.class); Vector3f normal = Stack.alloc(Vector3f.class); tmp1.sub(vertices1[1], vertices1[0]); tmp2.sub(vertices1[2], vertices1[0]); normal.cross(tmp1, tmp2); normal.normalize(); plane.set(normal.x, normal.y, normal.z, vertices1[0].dot(normal)); }
public PlaneIntersectionType plane_classify(Vector4f plane) { Vector3f tmp = Stack.alloc(Vector3f.class); float[] _fmin = new float[1], _fmax = new float[1]; tmp.set(plane.x, plane.y, plane.z); projection_interval(tmp, _fmin, _fmax); if (plane.w > _fmax[0] + BOX_PLANE_EPSILON) { return PlaneIntersectionType.BACK_PLANE; // 0 } if (plane.w + BOX_PLANE_EPSILON >= _fmin[0]) { return PlaneIntersectionType.COLLIDE_PLANE; //1 } return PlaneIntersectionType.FRONT_PLANE; //2 }
/** * Calc a plane from a triangle edge an a normal. */ public static void edge_plane(Vector3f e1, Vector3f e2, Vector3f normal, Vector4f plane) { Vector3f planenormal = Stack.alloc(Vector3f.class); planenormal.sub(e2, e1); planenormal.cross(planenormal, normal); planenormal.normalize(); plane.set(planenormal); plane.w = e2.dot(planenormal); }
/** * Line plane collision. * * @return -0 if the ray never intersects, -1 if the ray collides in front, -2 if the ray collides in back */ public static int line_plane_collision(Vector4f plane, Vector3f vDir, Vector3f vPoint, Vector3f pout, float[] tparam, float tmin, float tmax) { float _dotdir = VectorUtil.dot3(vDir, plane); if (Math.abs(_dotdir) < PLANEDIREPSILON) { tparam[0] = tmax; return 0; } float _dis = ClipPolygon.distance_point_plane(plane, vPoint); int returnvalue = _dis < 0.0f ? 2 : 1; tparam[0] = -_dis / _dotdir; if (tparam[0] < tmin) { returnvalue = 0; tparam[0] = tmin; } else if (tparam[0] > tmax) { returnvalue = 0; tparam[0] = tmax; } pout.scaleAdd(tparam[0], vDir, vPoint); return returnvalue; }
/** * Returns a texture coordinates generator that wraps the given texture on front face. */ private TexCoordGeneration getTextureCoordinates(Appearance appearance, HomeTexture texture, Vector3f pieceSize, BoundingBox modelBounds) { Point3d lower = new Point3d(); modelBounds.getLower(lower); Point3d upper = new Point3d(); modelBounds.getUpper(upper); float minimumSize = ModelManager.getInstance().getMinimumSize(); float textureWidth = TextureManager.getInstance().getRotatedTextureWidth(texture); float textureHeight = TextureManager.getInstance().getRotatedTextureHeight(texture); float sx = pieceSize.x / (float) Math.max(upper.x - lower.x, minimumSize) / textureWidth; float sw = texture.isLeftToRightOriented() ? (float) -lower.x * sx : 0; float ty = pieceSize.y / (float) Math.max(upper.y - lower.y, minimumSize) / textureHeight; float tz = pieceSize.z / (float) Math.max(upper.z - lower.z, minimumSize) / textureHeight; float tw = texture.isLeftToRightOriented() ? (float) (-lower.y * ty + upper.z * tz) : 0; return new TexCoordGeneration(TexCoordGeneration.OBJECT_LINEAR, TexCoordGeneration.TEXTURE_COORDINATE_2, new Vector4f(sx, 0, 0, sw), new Vector4f(0, ty, -tz, tw)); }
/** * Given a point in world coordinates, adjust it in place to be in * screen coordinates (after projection). * * @param point */ public void mapWorldToScreen( Camera view, Point3f point ) { Matrix4d viewMatrix = new Matrix4d(); this .view .getViewTransform( viewMatrix, 0d ); Transform3D viewTrans = new Transform3D( viewMatrix ); viewTrans .transform( point ); // point is now in view coordinates Vector4f p4 = new Vector4f( point.x, point.y, point.z, 1f ); Transform3D eyeTrans = new Transform3D(); if ( ! view .isPerspective() ) { double edge = view .getWidth() / 2; eyeTrans .ortho( -edge, edge, -edge, edge, view .getNearClipDistance(), view .getFarClipDistance() ); } else eyeTrans .perspective( view .getFieldOfView(), 1.0d, view .getNearClipDistance(), view .getFarClipDistance() ); // TODO - make aspect ratio track the screen window shape eyeTrans .transform( p4 ); point .project( new Point4f( p4 ) ); }
public Vertex transform(Matrix4f matrix, boolean rescaleToUnitCube) { Vector4f tmp = new Vector4f((float) x, (float) y, (float) z, 1f); matrix.transform(tmp); if (rescaleToUnitCube && Math.abs(tmp.w - 1f) > 1e-5) { tmp.scale(1f / tmp.w); } if(this.hasNormal()) { Vector4f tmpNormal = new Vector4f((float)this.normal.x, (float)this.normal.y, (float)this.normal.z, 1f); matrix.transform(tmp); Vec3d newNormal = new Vec3d(tmpNormal.x, tmpNormal.y, tmpNormal.z); newNormal.normalize(); return new Vertex(tmp.x, tmp.y, tmp.z, u, v, color, newNormal); } else { return new Vertex(tmp.x, tmp.y, tmp.z, u, v, color); } }
/** * Create a basic instance of this class with the list initial internal * setup for the given number of renderable surfaces. The size is just an * initial esstimate, and is used for optimisation purposes to prevent * frequent array reallocations internally. As such, the number does not * have to be perfect, just good enough. * * @param numSurfaces Total number of surfaces to prepare rendering for * @param useGlobalView The rendered viewpoint is set to look down on the * entire scene if set true, otherwise uses the normal value */ public DebugFrustumCullStage(int numSurfaces, boolean useGlobalView) { super(numSurfaces); viewMatrix = new Matrix4f(); prjMatrix = new Matrix4f(); frustumPoints = new Point4f[8]; for(int i=0; i < 8; i++) frustumPoints[i] = new Point4f(); frustumPlanes = new Vector4f[6]; for(int i=0; i < 6; i++) frustumPlanes[i] = new Vector4f(); t1 = new float[3]; t2 = new float[3]; c1 = new float[3]; c2 = new float[3]; globalViewpoint = useGlobalView; }
/** * Copies all node information from <code>originalNodeComponent</code> into * the current node. This method is called from the * <code>duplicateNode</code> method. This routine does * the actual duplication of all "local data" (any data defined in * this object). * * @param originalNodeComponent the original node to duplicate. * @param forceDuplicate when set to <code>true</code>, causes the * <code>duplicateOnCloneTree</code> flag to be ignored. When * <code>false</code>, the value of each node's * <code>duplicateOnCloneTree</code> variable determines whether * NodeComponent data is duplicated or copied. * * @see Node#cloneTree * @see NodeComponent#setDuplicateOnCloneTree */ void duplicateAttributes(NodeComponent originalNodeComponent, boolean forceDuplicate) { super.duplicateAttributes(originalNodeComponent, forceDuplicate); TexCoordGenerationRetained tex = (TexCoordGenerationRetained) originalNodeComponent.retained; TexCoordGenerationRetained rt = (TexCoordGenerationRetained) retained; Vector4f v = new Vector4f(); rt.initGenMode(tex.getGenMode()); tex.getPlaneS(v); rt.initPlaneS(v); tex.getPlaneT(v); rt.initPlaneT(v); tex.getPlaneR(v); rt.initPlaneR(v); tex.getPlaneQ(v); rt.initPlaneQ(v); rt.initFormat(tex.getFormat()); rt.initEnable(tex.getEnable()); }
@Override public void onCreateInventoryHook(UIWindow parent) { inventoryParent = parent; GridLayout layout = new GridLayout(10); //layout.setPadding(new Vector4f(0f, 2f, 2f, 2f)); inventoryContainer = new UICompositeScrollable(); inventoryContainer.setHorizontalAlign(UIDisplayElement.EHorizontalAlign.CENTER); inventoryContainer.setVerticalAlign(UIDisplayElement.EVerticalAlign.CENTER); inventoryContainer.setSize(new Vector2f(495, 288)); inventoryContainer.setBorderImage("engine:inventory", new Vector2f(0f, 84f), new Vector2f(169f, 61f), new Vector4f(5f, 4f, 3f, 4f)); inventoryContainer.setEnableScrolling(true); inventoryContainer.setEnableScrollbar(true); inventoryContainer.setLayout(layout); inventoryContainer.setPadding(new Vector4f(0f, 15f, 0f, 0f)); inventoryContainer.setVisible(true); fillInventoryCells(); inventoryParent.addDisplayElement(inventoryContainer); }
private void constructHorizontalBlocks(AssetUri blockDefUri, BlockDefinition blockDef, Map<Side, Block> blockMap) { Map<BlockPart, AssetUri> tileUris = prepareTiles(blockDef, blockDefUri); Map<BlockPart, Block.ColorSource> colorSourceMap = prepareColorSources(blockDef); Map<BlockPart, Vector4f> colorOffsetsMap = prepareColorOffsets(blockDef); BlockShape shape = getShape(blockDef); for (Rotation rot : Rotation.horizontalRotations()) { Block block = createRawBlock(blockDef, properCase(blockDefUri.getAssetName())); block.setDirection(rot.rotate(Side.FRONT)); applyShape(block, shape, tileUris, rot); for (BlockPart part : BlockPart.values()) { block.setColorSource(part, colorSourceMap.get(part)); block.setColorOffset(part, colorOffsetsMap.get(part)); } blockMap.put(rot.rotate(Side.FRONT), block); } }
protected void renderParticle(Particle particle, byte blockType, float temperature, float humidity, float light) { int displayList = displayLists.get(BlockManager.getInstance().getBlock(blockType).getBlockFamily()); if (displayList == 0) { displayList = glGenLists(1); glNewList(displayList, GL11.GL_COMPILE); drawParticle(blockType); glEndList(); displayLists.put(BlockManager.getInstance().getBlock(blockType).getBlockFamily(), displayList); } ShaderProgram shader = ShaderManager.getInstance().getShaderProgram("particle"); Vector4f color = BlockManager.getInstance().getBlock(blockType).calcColorOffsetFor(BlockPart.FRONT, temperature, humidity); shader.setFloat3("colorOffset", color.x, color.y, color.z); shader.setFloat("texOffsetX", particle.texOffset.x); shader.setFloat("texOffsetY", particle.texOffset.y); shader.setFloat("light", light); glCallList(displayList); }
public static void addGUIQuadMesh(Tessellator tessellator, Vector4f color, float sizeX, float sizeY) { tessellator.resetParams(); tessellator.setColor(new Vector4f(color.x, color.y, color.z, color.w)); tessellator.setUseLighting(false); tessellator.setUseNormals(false); tessellator.addPoly( new Vector3f[]{ new Vector3f(0, 0, 0), new Vector3f(sizeX, 0, 0), new Vector3f(sizeX, sizeY, 0), new Vector3f(0, sizeY, 0) }, new Vector2f[]{ new Vector2f(0, 0), new Vector2f(1, 0), new Vector2f(1, 1), new Vector2f(0, 1) } ); tessellator.setUseLighting(true); tessellator.setUseNormals(true); }
public AnimationOpacity(float fromOpacity, float toOpacity, float speed){ this.fromOpacity = fromOpacity; this.toOpacity = toOpacity; this.speed = speed; this.id = generateId(); if(fromOpacity<toOpacity){ this.factor = 1; }else{ this.factor = -1; } Tessellator tessellator = new Tessellator(); TessellatorHelper.addGUIQuadMesh(tessellator, new Vector4f(255f / 256f, 255f / 256f, 255f / 256f, 1.0f), 1.0f, 1.0f); mesh = tessellator.generateMesh(); currentOpacity = fromOpacity; }
/** * Set the border from an image. * @param texture The texture. * @param origin The origin of the border in the texture. * @param size The size of the border container in the texture. * @param width The border width for each side. x = top, y = right, z = bottom, w = left */ public void setBorderImage(String texture, Vector2f origin, Vector2f size, Vector4f borderSize) { StyleBorderImage style = getStyle(StyleBorderImage.class); if (style == null) { style = new StyleBorderImage(Assets.getTexture(texture)); style.setBorderSource(origin, size, borderSize); style.setVisible(true); addStyle(style); } else { //check if same texture is already loaded if (!style.getTexture().getURI().toString().equals("texture:" + texture)) { style.setTexture(Assets.getTexture(texture)); } style.setBorderSource(origin, size, borderSize); } }
/** * Set the source origin, size and border width of the image. * @param origin The origin in the texture. * @param size The size of the border container in the texture. * @param width The border width. x = top, y = right, z = bottom, w = left */ public void setBorderSource(Vector2f origin, Vector2f size, Vector4f width) { this.sourceOrigin = origin; this.sourceSize = size; this.width = width; sourceFrame("top"); sourceFrame("bottom"); sourceFrame("right"); sourceFrame("left"); sourceCorner("top-left"); sourceCorner("top-right"); sourceCorner("bottom-left"); sourceCorner("bottom-right"); }
protected static void putVertexData(UnpackedBakedQuad.Builder builder, Vector3f pos, EnumFacing facing, float u, float v, TextureAtlasSprite sprite, Color col, TRSRTransformation transform) { for (int e = 0; e < builder.getVertexFormat().getElementCount(); e++) switch (builder.getVertexFormat().getElement(e).getUsage()) { case POSITION: if (transform == TRSRTransformation.identity()) { builder.put(e, pos.getX(), pos.getY(), pos.getZ(), 1F); } else { Vector4f vec = new Vector4f(); vec.x = pos.x; vec.y = pos.y; vec.z = pos.z; vec.w = 1; transform.getMatrix().transform(vec); builder.put(e, vec.x, vec.y, vec.z, vec.w); } break; case COLOR: float r = ((col.getRGB() >> 16) & 0xFF) / 255f; // red float g = ((col.getRGB()>> 8) & 0xFF) / 255f; // green float b = ((col.getRGB() >> 0) & 0xFF) / 255f; // blue float a = ((col.getRGB() >> 24) & 0xFF) / 255f; // alpha builder.put(e, r, g, b, a); break; case UV: if (builder.getVertexFormat().getElement(e).getIndex() == 0) { builder.put(e, u, v, 0F, 1F); break; } break; case NORMAL: Normal normal = new Normal(facing.getDirectionVec().getX(), facing.getDirectionVec().getY(), facing.getDirectionVec().getZ()); builder.put(e, normal.x, normal.y, normal.z, 0); break; default: builder.put(e); } }
public static void transform(org.lwjgl.util.vector.Vector3f vec, Matrix4f m) { Vector4f tmp = new Vector4f(vec.x, vec.y, vec.z, 1f); m.transform(tmp); if(Math.abs(tmp.w - 1f) > 1e-5) tmp.scale(1f / tmp.w); vec.set(tmp.x, tmp.y, tmp.z); }
public void changeMaterialColor(String name, int color) { Vector4f colorVec = new Vector4f(); colorVec.w = (color >> 24 & 255) / 255; colorVec.x = (color >> 16 & 255) / 255; colorVec.y = (color >> 8 & 255) / 255; colorVec.z = (color & 255) / 255; this.materials.get(name).setColor(colorVec); }
private void putVertex(UnpackedBakedQuad.Builder builder, EnumFacing side, float x, float y, float z, float u, float v) { for(int e = 0; e < format.getElementCount(); e++) { switch(format.getElement(e).getUsage()) { case POSITION: float[] data = new float[]{ x - side.getDirectionVec().getX() * eps, y, z - side.getDirectionVec().getZ() * eps, 1 }; if(transformation.isPresent() && transformation.get() != TRSRTransformation.identity()) { Vector4f vec = new Vector4f(data); transformation.get().getMatrix().transform(vec); vec.get(data); } builder.put(e, data); break; case COLOR: builder.put(e, ((color >> 16) & 0xFF) / 255f, ((color >> 8) & 0xFF) / 255f, (color & 0xFF) / 255f, ((color >> 24) & 0xFF) / 255f); break; case UV: if(format.getElement(e).getIndex() == 0) { builder.put(e, u, v, 0f, 1f); break; } case NORMAL: builder.put(e, (float)side.getFrontOffsetX(), (float)side.getFrontOffsetY(), (float)side.getFrontOffsetZ(), 0f); break; default: builder.put(e); break; } } }