use of org.gephi.lib.gleem.linalg.Vec3f in project gephi by gephi.
the class Octree method updateVisibleOctant.
public void updateVisibleOctant(GL2 gl) {
if (leavesCount > 0) {
//Limits
refreshLimits();
//Switch to OpenGL2 select mode
//Each object take in maximium : 4 * name stack depth
int capacity = 1 * 4 * leavesCount;
IntBuffer hitsBuffer = Buffers.newDirectIntBuffer(capacity);
gl.glSelectBuffer(hitsBuffer.capacity(), hitsBuffer);
gl.glRenderMode(GL2.GL_SELECT);
gl.glInitNames();
gl.glPushName(0);
//Disable flags
gl.glDisable(GL2.GL_CULL_FACE);
//Draw the nodes cube in the select buffer
for (Octant n : leaves) {
if (n != null) {
gl.glLoadName(n.leafId);
n.displayOctant(gl);
n.visible = false;
}
}
visibleLeaves = 0;
int nbRecords = gl.glRenderMode(GL2.GL_RENDER);
//Get the hits and add the nodes' objects to the array
int depth = Integer.MAX_VALUE;
int minDepth = -1;
for (int i = 0; i < nbRecords; i++) {
//-1 Because of the glPushName(0)
int hit = hitsBuffer.get(i * 4 + 3);
int minZ = hitsBuffer.get(i * 4 + 1);
if (minZ < depth) {
depth = minZ;
minDepth = hit;
}
Octant nodeHit = leaves[hit];
nodeHit.visible = true;
visibleLeaves++;
}
if (minDepth != -1) {
Octant closestOctant = leaves[minDepth];
Vec3f pos = new Vec3f(closestOctant.getPosX(), closestOctant.getPosY(), closestOctant.getPosZ());
limits.setClosestPoint(pos);
}
}
}
use of org.gephi.lib.gleem.linalg.Vec3f in project gephi by gephi.
the class StandardGraphIO method mouseWheelMoved.
@Override
public void mouseWheelMoved(MouseEvent e) {
float scroll = e.getRotation()[1];
if (scroll == 0f || !vizController.getVizConfig().isCameraControlEnable()) {
return;
}
boolean ctrl = (e.getModifiers() & InputEvent.CTRL_DOWN_MASK) != 0 || (e.getModifiers() & InputEvent.CTRL_MASK) != 0 || (e.getModifiers() & InputEvent.META_MASK) != 0;
if (ctrl) {
SelectionManager manager = VizController.getInstance().getSelectionManager();
if (!manager.isRectangleSelection()) {
int s = manager.getMouseSelectionDiameter();
s += scroll * 2;
s = Math.min(1000, s);
s = Math.max(1, s);
manager.setMouseSelectionDiameter(s);
}
return;
}
//Attributes
float globalScale = graphDrawable.getGlobalScale();
float way = scroll / Math.abs(scroll);
float[] cameraLocation = graphDrawable.getCameraLocation();
float[] cameraTarget = graphDrawable.getCameraTarget();
float markerX = (float) graphDrawable.getDraggingMarkerX();
float markerY = (float) graphDrawable.getDraggingMarkerY();
//Transform in 3d coordinates
//Set to centric coordinates
float mouseX = (float) ((mousePosition[0] - graphDrawable.viewport.get(2) / 2.0) / -markerX) + cameraTarget[0] / globalScale;
float mouseY = (float) ((mousePosition[1] - graphDrawable.viewport.get(3) / 2.0) / -markerY) + cameraTarget[1] / globalScale;
//Get mouse position within the clipping plane
mouseX = MathUtil.clamp(mouseX, limits.getMinXoctree(), limits.getMaxXoctree());
mouseY = MathUtil.clamp(mouseY, limits.getMinYoctree(), limits.getMaxYoctree());
mouseX *= globalScale;
mouseY *= globalScale;
//Camera location and target vectors
Vec3f targetVector = new Vec3f(mouseX - cameraTarget[0], mouseY - cameraTarget[1], 0f);
Vec3f locationVector = new Vec3f(mouseX - cameraLocation[0], mouseY - cameraLocation[1], -cameraLocation[2]);
//Distance from location to mouse
float distance = (float) Math.sqrt(locationVector.x() * locationVector.x() + locationVector.y() * locationVector.y() + locationVector.z() * locationVector.z());
float distanceRatio = MathUtil.clamp(2 * distance / 10000f, 0f, 2f);
//exp(x-2)*2.2-0.3
float coeff = (float) (Math.exp(distanceRatio - 2) * 2.2 - 0.295);
float step = way * (10f + 1000 * coeff);
if (way == -1) {
step *= 3;
}
float stepRatio = step / distance;
//Multiply vectors
targetVector.scale(stepRatio);
locationVector.scale(stepRatio);
if (cameraLocation[2] + locationVector.z() >= 1f && cameraLocation[2] + locationVector.z() <= (graphDrawable.farDistance - graphDrawable.nearDistance)) {
cameraLocation[0] += locationVector.x();
cameraLocation[1] += locationVector.y();
cameraLocation[2] += locationVector.z();
cameraTarget[0] += targetVector.x();
cameraTarget[1] += targetVector.y();
}
//Refresh
engine.getScheduler().requireUpdateVisible();
}
use of org.gephi.lib.gleem.linalg.Vec3f in project gephi by gephi.
the class StandardGraphIO method setCameraDistance.
@Override
public void setCameraDistance(float distance) {
float[] cameraLocation = graphDrawable.getCameraLocation();
float[] cameraTarget = graphDrawable.getCameraTarget();
Vec3f camVect = new Vec3f(cameraTarget[0] - cameraLocation[0], cameraTarget[1] - cameraLocation[1], cameraTarget[2] - cameraLocation[2]);
float diff = camVect.length() - distance;
if (Math.abs(diff) > 1f) {
camVect.normalize();
cameraLocation[0] += camVect.x() * diff;
cameraLocation[1] += camVect.y() * diff;
cameraLocation[2] += camVect.z() * diff;
cameraLocation[2] = Math.max(0.5f, cameraLocation[2]);
engine.getScheduler().requireUpdateVisible();
}
}
Aggregations