com.daxie.joglf.gl.drawer.DynamicCapsulesDrawer Maven / Gradle / Ivy
package com.daxie.joglf.gl.drawer;
import java.nio.Buffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;
import com.daxie.basis.coloru8.ColorU8;
import com.daxie.basis.matrix.Matrix;
import com.daxie.basis.matrix.MatrixFunctions;
import com.daxie.basis.vector.Vector;
import com.daxie.basis.vector.VectorFunctions;
import com.daxie.joglf.gl.shader.GLShaderFunctions;
import com.daxie.joglf.gl.shape.Capsule;
import com.daxie.joglf.gl.wrapper.GLWrapper;
import com.daxie.log.LogFile;
import com.jogamp.common.nio.Buffers;
import com.jogamp.opengl.GL4;
/**
* Draws capsules.
* @author Daba
*
*/
public class DynamicCapsulesDrawer extends Dynamic3DDrawer{
private Map capsules_map;
private Map indices_sizes_map;
private int buffer_num;
private IntBuffer indices_vbo;
private IntBuffer pos_vbo;
private IntBuffer dif_vbo;
private IntBuffer vao;
public DynamicCapsulesDrawer() {
capsules_map=new TreeMap<>();
indices_sizes_map=new HashMap<>();
buffer_num=0;
}
@Override
public void SetDefaultProgram() {
this.RemoveAllShaders();
this.AddProgram("color");
}
@Override
public void UpdateBuffers() {
int capsule_num=capsules_map.size();
if(buffer_num!=0)this.DeleteBuffers();
indices_vbo=Buffers.newDirectIntBuffer(capsule_num);
pos_vbo=Buffers.newDirectIntBuffer(capsule_num);
dif_vbo=Buffers.newDirectIntBuffer(capsule_num);
vao=Buffers.newDirectIntBuffer(capsule_num);
GLWrapper.glGenBuffers(capsule_num, indices_vbo);
GLWrapper.glGenBuffers(capsule_num, pos_vbo);
GLWrapper.glGenBuffers(capsule_num, dif_vbo);
GLWrapper.glGenVertexArrays(capsule_num, vao);
buffer_num=capsule_num;
int buffer_count=0;
for(Capsule capsule:capsules_map.values()) {
Vector capsule_pos_1=capsule.GetCapsulePos1();
Vector capsule_pos_2=capsule.GetCapsulePos2();
float radius=capsule.GetRadius();
int slice_num=capsule.GetSliceNum();
int stack_num=capsule.GetStackNum();
ColorU8 color=capsule.GetColor();
Vector capsule_axis=VectorFunctions.VSub(capsule_pos_2, capsule_pos_1);
float d=VectorFunctions.VSize(capsule_axis);
float half_d=d/2.0f;
float th_v=VectorFunctions.VAngleV(capsule_axis);
float th_h=VectorFunctions.VAngleH(capsule_axis);
Vector center_pos=VectorFunctions.VAdd(capsule_pos_1, capsule_pos_2);
center_pos=VectorFunctions.VScale(center_pos, 0.5f);
List vertices=new ArrayList<>();
List indices=new ArrayList<>();
int vertex_num=slice_num*(stack_num-1)+2;
//North pole
vertices.add(VectorFunctions.VGet(0.0f, radius+half_d, 0.0f));
//Middle
for(int i=1;i program_names=this.GetProgramNames();
for(String program_name:program_names) {
GLShaderFunctions.UseProgram(program_name);
for(int i=0;i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy