Java Code Examples for org.lwjgl.util.vector.Matrix4f#setIdentity()

The following examples show how to use org.lwjgl.util.vector.Matrix4f#setIdentity() . 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: Manipulator.java    From ldparteditor with MIT License 6 votes vote down vote up
public void resetTranslation() {
    accurateResult = View.ACCURATE_ID;
    accurateScale = View.ACCURATE_ID;
    accurateRotationX = 0.0;
    accurateRotationY = 0.0;
    accurateRotationZ = 0.0;
    Matrix4f.setIdentity(result);
    Matrix4f.setIdentity(scale);
    x_Translate = false;
    y_Translate = false;
    z_Translate = false;
    x_Rotate = false;
    y_Rotate = false;
    z_Rotate = false;
    x_Scale = false;
    y_Scale = false;
    z_Scale = false;

    x_rotatingForwards = false;
    x_rotatingBackwards = false;
    y_rotatingForwards = false;
    y_rotatingBackwards = false;
    z_rotatingForwards = false;
    z_rotatingBackwards = false;
    modified = false;
}
 
Example 2
Source File: Maths.java    From LowPolyWater with The Unlicense 5 votes vote down vote up
public static void updateViewMatrix(Matrix4f viewMatrix, float x, float y, float z, float pitch, float yaw){
	viewMatrix.setIdentity();
	Matrix4f.rotate((float) Math.toRadians(pitch), new Vector3f(1, 0, 0), viewMatrix, viewMatrix);
	Matrix4f.rotate((float) Math.toRadians(yaw), new Vector3f(0, 1, 0), viewMatrix, viewMatrix);
	Vector3f negativeCameraPos = new Vector3f(-x, -y, -z);
	Matrix4f.translate(negativeCameraPos, viewMatrix, viewMatrix);
}
 
Example 3
Source File: CSG.java    From ldparteditor with MIT License 5 votes vote down vote up
public GData1 compile() {
    Matrix4f id = new Matrix4f();
    Matrix4f.setIdentity(id);
    GColour col = View.getLDConfigColour(16);
    GData1 g1 = new GData1(-1, col.getR(), col.getG(), col.getB(), 1f, id, View.ACCURATE_ID, new ArrayList<String>(), null, null, 1, false, id, View.ACCURATE_ID, null, View.DUMMY_REFERENCE, true, false,
            new HashSet<String>(), View.DUMMY_REFERENCE);
    this.result = toLDrawTriangles(g1);
    return g1;
}
 
Example 4
Source File: Manipulator.java    From ldparteditor with MIT License 5 votes vote down vote up
public void startTranslation(Composite3D c3d) {
    initialScaleOld = initialScaleNew;
    c3d.getLockableDatFileReference().getVertexManager().backupHideShowState();
    modified = false;
    Matrix4f.setIdentity(result);
    Matrix4f.setIdentity(scale);
    accurateResult = View.ACCURATE_ID;
    accurateScale = View.ACCURATE_ID;
    accurateRotationX = 0.0;
    accurateRotationY = 0.0;
    accurateRotationZ = 0.0;
}
 
Example 5
Source File: PerspectiveCalculator.java    From ldparteditor with MIT License 5 votes vote down vote up
/**
 * @return The real transformation matrix of the viewport
 */
public Matrix4f getRealViewport() {
    Matrix4f viewport_transform = new Matrix4f();
    Matrix4f.setIdentity(viewport_transform);
    float zoom = c3d.getZoom();
    Matrix4f.scale(new Vector3f(zoom, zoom, zoom), viewport_transform, viewport_transform);
    Matrix4f viewport_rotation = c3d.getRotation();
    Matrix4f.mul(viewport_rotation, viewport_transform, viewport_transform);
    Matrix4f viewport_translation = c3d.getTranslation();
    Matrix4f.mul(viewport_transform, viewport_translation, viewport_transform);
    return viewport_transform;
}
 
Example 6
Source File: Composite3DModifier.java    From ldparteditor with MIT License 5 votes vote down vote up
public void zoomToFit() {
    final PerspectiveCalculator pc = c3d.getPerspectiveCalculator();
    float max_x = 0f;
    float max_y = 0f;
    for (Vertex v : c3d.getLockableDatFileReference().getVertexManager().getVertices()) {
        float ax = Math.abs(v.x);
        float ay = Math.abs(v.y);
        if (ax > max_x) max_x = ax;
        if (ay > max_y) max_y = ay;
    }
    Matrix4f id = new Matrix4f();
    Matrix4f.setIdentity(id);
    c3d.getTranslation().load(id);
    Rectangle b = c3d.getBounds();
    if (max_x > max_y) {
        c3d.setZoom(b.width / (max_x * 4f * View.PIXEL_PER_LDU));
    } else {
        c3d.setZoom(b.height / (max_y * 4f * View.PIXEL_PER_LDU));
    }
    pc.setZoom_exponent((float) (Math.log10(c3d.getZoom()) + 3f) * 10f);

    if (Float.isInfinite(c3d.getZoom()) || Float.isInfinite(pc.getZoom_exponent()) || Float.isNaN(c3d.getZoom()) || Float.isNaN(pc.getZoom_exponent())) {
        pc.setZoom_exponent(-20f);
        c3d.setZoom((float) Math.pow(10.0d, -20f / 10 - 3));
    }

    c3d.setViewportPixelPerLDU(c3d.getZoom() * View.PIXEL_PER_LDU);
    GuiStatusManager.updateStatus(c3d);
    ((ScalableComposite) c3d.getParent()).redrawScales();
    pc.initializeViewportPerspective();
    syncZoom();
}
 
Example 7
Source File: GDataCSG.java    From ldparteditor with MIT License 5 votes vote down vote up
public static void rebuildSelection(DatFile df) {
    final Composite3D c3d = df.getLastSelectedComposite();
    if (c3d == null || df.getLastSelectedComposite().isDisposed()) return;
    final HashSet<GData3> selectedTriangles = selectedTrianglesMap.putIfAbsent(df, new HashSet<GData3>());
    final HashSet<GDataCSG> selectedBodies = selectedBodyMap.get(df);
    selectedTriangles.clear();
    if (selectedBodies != null) {
        try {
            for (GDataCSG c : selectedBodies) {
                if (c == null) {
                    selectedTriangles.clear();
                    selectedBodies.clear();
                    return;
                }
                if (c.dataCSG == null) {
                    selectedTriangles.clear();
                } else {
                    for (Polygon p : c.dataCSG.getPolygons()) {
                        Matrix4f id = new Matrix4f();
                        Matrix4f.setIdentity(id);
                        GData1 g1 = new GData1(-1, .5f, .5f, .5f, 1f, id, View.ACCURATE_ID, new ArrayList<String>(), null, null, 1, false, id, View.ACCURATE_ID, null, View.DUMMY_REFERENCE, true, false,
                                new HashSet<String>(), View.DUMMY_REFERENCE);
                        selectedTriangles.addAll(p.toLDrawTriangles(g1).keySet());
                    }
                }
            }
            if (selectedTriangles.isEmpty()) {
                selectedBodies.clear();
            }
        } catch (ConcurrentModificationException consumed) {

        }
    }
}
 
Example 8
Source File: Particle.java    From tribaltrouble with GNU General Public License v2.0 5 votes vote down vote up
public Particle(float angle) {
	Matrix4f rot_matrix = new Matrix4f();
	Vector3f axis = new Vector3f();
	Vector4f uv_vector = new Vector4f();
	Vector4f transform_uv_vector = new Vector4f();
	
	rot_matrix.setIdentity();
	axis.set(0f, 0f, 1f);
	rot_matrix.rotate(angle, axis);

	uv_vector.set(-.5f, -.5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u1 = transform_uv_vector.getX() + .5f;
	v1 = transform_uv_vector.getY() + .5f;
	
	uv_vector.set(.5f, -.5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u2 = transform_uv_vector.getX() + .5f;
	v2 = transform_uv_vector.getY() + .5f;

	uv_vector.set(.5f, .5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u3 = transform_uv_vector.getX() + .5f;
	v3 = transform_uv_vector.getY() + .5f;

	uv_vector.set(-.5f, .5f, 0f, 0f);
	Matrix4f.transform(rot_matrix, uv_vector, transform_uv_vector);
	u4 = transform_uv_vector.getX() + .5f;
	v4 = transform_uv_vector.getY() + .5f;
}
 
Example 9
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 10
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 11
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 12
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 13
Source File: vboWithRGBA.java    From ldparteditor with MIT License 4 votes vote down vote up
@Override
public void init() {
    
    Matrix4f.setIdentity(viewport);
    shaderProgram = new GLShader("primitive.vert", "primitive.frag"); //$NON-NLS-1$ //$NON-NLS-2$
    shaderProgram.use();
    
    GL11.glClearDepth(1.0f);
    GL11.glClearColor(View.primitive_background_Colour_r[0], View.primitive_background_Colour_g[0], View.primitive_background_Colour_b[0], 1.0f);
    
    // Set up vertex data (and buffer(s)) and attribute pointers
    float[] vertices = new float[]{
         0.5f,  0.5f, 0.0f,  // Top Right
         0.0f,  0.0f, 1.0f,  // Normal
         1.0f, 0.0f, 0.0f, 1.0f, // Colour
         
         0.5f, -0.5f, 0.0f,  // Bottom Right
         0.0f,  0.0f, 1.0f,  // Normal
         0.0f, 1.0f, 0.0f, 1.0f, // Colour
         
        -0.5f, -0.5f, 0.0f,  // Bottom Left
        0.0f,  0.0f, 1.0f,  // Normal
        0.0f, 0.0f, 1.0f, 1.0f, // Colour
    };
    
    VAO = GL30.glGenVertexArrays();
    VBO = GL15.glGenBuffers();
    // Bind the Vertex Array Object first, then bind and set vertex buffer(s) and attribute pointer(s).
    GL30.glBindVertexArray(VAO);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, VBO);
    GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vertices, GL15.GL_STATIC_DRAW);

    GL20.glEnableVertexAttribArray(POSITION_SHADER_LOCATION);
    GL20.glVertexAttribPointer(POSITION_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, 0);
    
    GL20.glEnableVertexAttribArray(NORMAL_SHADER_LOCATION);
    GL20.glVertexAttribPointer(NORMAL_SHADER_LOCATION, 3, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, 3 * 4);
    
    GL20.glEnableVertexAttribArray(COLOUR_SHADER_LOCATION);
    GL20.glVertexAttribPointer(COLOUR_SHADER_LOCATION, 4, GL11.GL_FLOAT, false, (3 + 3 + 4) * 4, (3 + 3) * 4);

    GL15.glBindBuffer(GL15.GL_ARRAY_BUFFER, 0); // Note that this is allowed, the call to glVertexAttribPointer registered VBO as the currently bound vertex buffer object so afterwards we can safely unbind

    GL30.glBindVertexArray(0); // Unbind VAO (it's always a good thing to unbind any buffer/array to prevent strange bugs), remember: do NOT unbind the EBO, keep it bound to this VAO

}
 
Example 14
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 15
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 16
Source File: Manipulator.java    From ldparteditor with MIT License 4 votes vote down vote up
public Manipulator() {
    Matrix4f.setIdentity(result);
    Matrix4f.setIdentity(scale);
}
 
Example 17
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 18
Source File: GDataPNG.java    From ldparteditor with MIT License 4 votes vote down vote up
public GDataPNG(String text, Vertex offset, BigDecimal angleA, BigDecimal angleB, BigDecimal angleC, Vertex scale, String texturePath, GData1 parent) {
    super(parent);
    this.text = text;
    this.texturePath = texturePath;
    this.texture = new GTexture(TexType.PLANAR, texturePath, null, 0, new Vector3f(), new Vector3f(), new Vector3f(), 0, 0);
    this.offset = offset;
    this.scale = scale;
    this.angleA = angleA;
    this.angleB = angleB;
    this.angleC = angleC;

    {
        Matrix4f tMatrix2 = new Matrix4f();
        tMatrix2.setIdentity();
        tMatrix = tMatrix2.scale(new Vector3f(scale.x, scale.y, scale.z));
    }

    Matrix4f dMatrix = new Matrix4f();
    dMatrix.setIdentity();

    Vector4f direction = new Vector4f(0f, 0f, -1f, 1f);
    // Matrix4f.rotate((float) (angleC.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 0f, 1f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleB.doubleValue() / 180.0 * Math.PI), new Vector3f(1f, 0f, 0f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleA.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 1f, 0f), dMatrix, dMatrix);

    Matrix4f.transform(dMatrix, direction, direction);
    direction.w = 0f;
    direction.normalise();
    direction.w = 1f;
    this.direction = direction;

    dMatrix.setIdentity();

    Matrix4f.rotate((float) (angleC.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 0f, 1f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleB.doubleValue() / 180.0 * Math.PI), new Vector3f(1f, 0f, 0f), dMatrix, dMatrix);
    Matrix4f.rotate((float) (angleA.doubleValue() / 180.0 * Math.PI), new Vector3f(0f, 1f, 0f), dMatrix, dMatrix);

    Matrix4f.mul(dMatrix, tMatrix, tMatrix);

    Vector4f vx = Matrix4f.transform(dMatrix, new Vector4f(offset.x, 0f, 0f, 1f), null);
    Vector4f vy = Matrix4f.transform(dMatrix, new Vector4f(0f, offset.y, 0f, 1f), null);
    Vector4f vz = Matrix4f.transform(dMatrix, new Vector4f(0f, 0f, offset.z, 1f), null);
    tMatrix.m30 = vx.x;
    tMatrix.m31 = vx.y;
    tMatrix.m32 = vx.z;
    tMatrix.m30 += vy.x;
    tMatrix.m31 += vy.y;
    tMatrix.m32 += vy.z;
    tMatrix.m30 += vz.x;
    tMatrix.m31 += vz.y;
    tMatrix.m32 += vz.z;

    matrix = BufferUtils.createFloatBuffer(16);
    tMatrix.store(matrix);

    matrix.position(0);
}
 
Example 19
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}
 
Example 20
Source File: FaceBakery.java    From The-5zig-Mod with MIT License 4 votes vote down vote up
private Matrix4f a() {
	Matrix4f var = new Matrix4f();
	var.setIdentity();
	return var;
}