Skip to content

Commit

Permalink
select with rectangle function, imitation of move func with OpenGL VBO
Browse files Browse the repository at this point in the history
  • Loading branch information
VVS1864 committed May 12, 2018
1 parent 8acdb1a commit def961a
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 14 deletions.
2 changes: 1 addition & 1 deletion samoJ/src/core/Dynamic_data.java
Expand Up @@ -55,7 +55,7 @@ public float[] get_floats(ArrayList<Float> vertices) {
float[] floatVertices = new float[vertices.size()];
int i = 0;
for (Float f : vertices) {
floatVertices[i++] = f;// (f != null ? f : Float.NaN); // Or whatever default you want.
floatVertices[i++] = f;
}
return floatVertices;

Expand Down
35 changes: 34 additions & 1 deletion samoJ/src/core/GL_base.java
Expand Up @@ -35,13 +35,17 @@ public class GL_base {
public ShaderState st;
private GLArrayDataServer interleavedVBO;
private GLArrayDataServer dynamic_interleavedVBO;
private GLArrayDataServer fast_dynamic_interleavedVBO;

public float[] general_matrix = { 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };

public float[] identity_matrix = { 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };

public float[] dynamic_matrix = { 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1, 0, 0, 0, 0, 1 };

public PMVMatrix pmvMatrix;
/**
* Variable for uniform location in shader program
Expand Down Expand Up @@ -272,7 +276,7 @@ public void update_dynamic_data(){
core.global.N_dynamic_lines = 0;
Dynamic_data d = new Dynamic_data(GL_version);

if (core.global.select_mode){
if (core.global.selective_rect.enable){
d.put_data(core.global.selective_rect.select_rect_vertices, core.global.selective_rect.select_rect_color.get_float_rgb(), core.values.select_rect_width);
}

Expand All @@ -287,6 +291,10 @@ public void update_dynamic_data(){
core.values.dynamic_width);
}

Dynamic_data fast_d = new Dynamic_data(GL_version);
if(core.global.fast_dynamic_vertices != null) {
fast_d.put_data(core.global.fast_dynamic_vertices, core.values.selected_shape_color.get_float_rgb(), core.values.dynamic_width);
}
if (GL_version == 3) {
float[] vertices = d.get_vertices();
float[] colors = d.get_colors();
Expand All @@ -300,6 +308,19 @@ public void update_dynamic_data(){
dynamic_interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 3 + 1, GL3.GL_FLOAT, false,
core.global.N_dynamic_lines * 2 * 3, GL3.GL_STATIC_DRAW);
update_vao(dynamic_interleavedVBO, vertices, colors, widths, core.global.N_dynamic_lines);

vertices = fast_d.get_vertices();
colors = fast_d.get_colors();
widths = fast_d.get_widths();
core.global.N_fast_dynamic_lines = vertices.length / 6;
// destroy old VBO (memory leak!)
if (null != fast_dynamic_interleavedVBO) {
st.ownAttribute(fast_dynamic_interleavedVBO, false);
fast_dynamic_interleavedVBO.destroy(gl3);
}
fast_dynamic_interleavedVBO = GLArrayDataServer.createGLSLInterleaved(3 + 3 + 1, GL3.GL_FLOAT, false,
core.global.N_fast_dynamic_lines * 2 * 3, GL3.GL_STATIC_DRAW);
update_vao(fast_dynamic_interleavedVBO, vertices, colors, widths, core.global.N_fast_dynamic_lines);
}
else if (GL_version < 3) {
for(GL1_2_data dataArray: d.GL1_2_dynamic_dataArray) {
Expand Down Expand Up @@ -412,6 +433,8 @@ public void render(int width, int height) {

draw_vao(interleavedVBO, core.global.N_DrawableLines);
draw_vao(dynamic_interleavedVBO, core.global.N_dynamic_lines);
draw_fast_dynamic(fast_dynamic_interleavedVBO, core.global.N_fast_dynamic_lines);

st.useProgram(gl3, false);

pmvMatrix.glGetFloatv(GLMatrixFunc.GL_MODELVIEW_MATRIX, mvmatrix, 0);
Expand All @@ -424,6 +447,16 @@ else if(GL_version < 3 ) {
}
}

private void draw_fast_dynamic(
GLArrayDataServer fast_dynamic_interleavedVBO,
int n_fast_dynamic_lines) {
pmvMatrix.glPushMatrix();
pmvMatrix.glMultMatrixf(dynamic_matrix, 0);
update_pmv_matrix();
draw_vao(fast_dynamic_interleavedVBO, core.global.N_fast_dynamic_lines);
pmvMatrix.glPopMatrix();
update_pmv_matrix();
}
public void dispose() {
if (GL_version == 3) {

Expand Down
32 changes: 25 additions & 7 deletions samoJ/src/core/GUI/mouse_event_listeners/Mouse_events.java
Expand Up @@ -10,6 +10,7 @@
import core.Core;
import core.Draw_snap_sign;
import core.Get_snap;
import core.dynamic_entities.Selective_rect;
import core.navigation.Plan_motion;
import samoJ.Shape;
import samoJ.SnapCoord;
Expand Down Expand Up @@ -89,13 +90,21 @@ public void mouseMoved(MouseEvent e) {
float y = core.global.cursor_coords[1];
// TO-DO snap to Shapes

///temp!!!
if (core.global.temp_move) {
float dx = core.global.point_1_coords[0] - x;
float dy = core.global.point_1_coords[1] - y;
core.glRender.dynamic_matrix = new float[]{ 1, 0, 0, 0, 0, 1,
0, 0, 0, 0, 1, 0, -dx, -dy, 0, 1 };
}

core.global.cursor_snap_coords = core.global.cursor_coords.clone();
if (core.global.mouse_plan_motion == false) {
core.gui.info_down.setText("Coordinates: X "
+ String.format("%.2f", x) + "; Y "
+ String.format("%.2f", y) + ";");

if (core.global.select_mode == true) {
if (core.global.selective_rect.enable == true) {
core.global.selective_rect.new_data(core.global.cursor_snap_coords);
}
else {
Expand All @@ -111,7 +120,7 @@ public void mouseMoved(MouseEvent e) {
// Current Shape indication - if not (select_mode,
// draw_new_object)
// and there are any Shapes under cursor
if (!core.global.select_mode && !core.global.draw_new_object
if (!core.global.selective_rect.enable && !core.global.draw_new_object
&& !current_Shapes.isEmpty()) {
core.global.current_Shape = current_Shapes.get(0);
// Make current shapeInteger for click-selecting
Expand Down Expand Up @@ -156,14 +165,23 @@ public void mouseMoved(MouseEvent e) {
}

void mouse_select(){
if (core.global.select_mode == false){
Selective_rect r = core.global.selective_rect;
if (r.enable == false){
//TO-DO block if object on cursor!!!
core.global.select_mode = true;
core.global.selective_rect.init(core.global.cursor_snap_coords, core.global.cursor_snap_coords);
r.init(core.global.cursor_snap_coords, core.global.cursor_snap_coords);
}
else {
core.global.select_mode = false;
core.global.selective_rect.clear();
r.clear();
LinkedList<Shape> current_Shapes = Clip_algorithm.simple_clip(r.get_x_min(), r.get_y_min(), r.get_x_max(), r.get_y_max(), core.global.theShapes);
FloatArrayList list1 = new FloatArrayList(0);
for(Shape sh: current_Shapes) {
list1.addAll(sh.toListFloat());
}
core.global.fast_dynamic_vertices = list1.elements();

///temp!!!
core.global.temp_move = true;
core.global.point_1_coords = core.global.cursor_coords.clone();
}

}
Expand Down
9 changes: 5 additions & 4 deletions samoJ/src/core/Global_var.java
Expand Up @@ -23,10 +23,6 @@ public class Global_var {
*/
public boolean draw_new_object = false;

/**
* True if program in select with rectangle state
*/
public boolean select_mode = false;

// Program global variables
/**
Expand Down Expand Up @@ -94,6 +90,8 @@ public class Global_var {
public float[] snap_sign_vertices = null;

public float[] preview_object_vertices = null;

public float[] fast_dynamic_vertices = null;

// COLORES
public Color_rgb select_rect_color = new Color_rgb(1.0f, 1.0f, 1.0f);
Expand All @@ -107,9 +105,12 @@ public class Global_var {

public int N_DrawableLines = 0;
public int N_dynamic_lines = 0;
public int N_fast_dynamic_lines = 0;

public int N = 50;// number of test lines

public boolean temp_move = false;

public Global_var() {

}
Expand Down
4 changes: 3 additions & 1 deletion samoJ/src/core/Program_state.java
Expand Up @@ -15,10 +15,12 @@ public class Program_state {
public void set_default(){
core.global.current_function = null;
core.global.preview_object_vertices = null;
core.global.fast_dynamic_vertices = null;
core.global.draw_new_object = false;
core.global.select_mode = false;
core.global.selective_rect.clear();
core.gui.info.setText("Comand:");
core.gui.info2.setText(" ");
core.gui.cmd.setText("");
core.global.temp_move = false;
}
}
1 change: 1 addition & 0 deletions samoJ/src/core/Values.java
Expand Up @@ -64,6 +64,7 @@ public class Values {
* Color for new object (Class Color_rgb!)
*/
public Color_rgb color = new Color_rgb(1f, 1f, 0f);//{255, 0, 0};
public Color_rgb selected_shape_color = new Color_rgb(0f, 0f, 1f);
public Color_rgb snap_color = new Color_rgb(0f, 1f, 1f);//{0, 255, 255};
/**
* Color for object under cursor
Expand Down
26 changes: 26 additions & 0 deletions samoJ/src/core/cursor.java
@@ -0,0 +1,26 @@
package core;

import samoJ.Coord;
/**
* Class container for cursor variables.
* @author vlad
*
*/
public class cursor extends Coord {
private Coord snap_coord;
private boolean plan_motion;



public cursor(float x, float y) {
super(x, y);

}

public cursor(float x, float y, float z) {
super(x, y, z);
}



}
16 changes: 16 additions & 0 deletions samoJ/src/core/dynamic_entities/Selective_rect.java
Expand Up @@ -5,6 +5,7 @@
public class Selective_rect {
public float[] select_rect_1;
public float[] select_rect_2;
public boolean enable = false;
/**
* Selective rectangle vertices for draw on canvas and select Shapes
*/
Expand All @@ -24,6 +25,7 @@ public void init(float[] point_1, float[] point_2) {
select_rect_1 = point_1.clone();
select_rect_2 = point_2.clone();
calc_rect();
enable = true;
}

public void new_data(float[] point_2) {
Expand Down Expand Up @@ -56,6 +58,20 @@ private void calc_rect() {

public void clear() {
select_rect_vertices = null;
enable = false;
}

public float get_x_min() {
return x1<x2 ? x1 : x2;
}
public float get_y_min() {
return y1<y2 ? y1 : y2;
}
public float get_x_max() {
return x1>x2 ? x1 : x2;
}
public float get_y_max() {
return y1>y2 ? y1 : y2;
}

}

0 comments on commit def961a

Please sign in to comment.