#version 330

#extension GL_EXT_geometry_shader4 : enable

precision highp float;

void createCircleGeometry(in vec4 v, in float f_size, in mat4 orientation)

{

int NVC = 9;

float fNVC = 9.;

float a = 0.;

float s = 3.1415 * 2. / fNVC;

for(int i=0; i<NVC; i++, a+=s)

{

//gl_Position = v + (gl_ModelViewProjectionMatrix * (orientation*vec4(cos(a)*f_size, sin(a)*f_size, 0., 0.)));

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(cos(a)*f_size, sin(a)*f_size, 0., 0.));

EmitVertex();

gl_Position = v;

EmitVertex();

}

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(cos(0)*f_size, sin(0)*f_size, 0., 0.));

EmitVertex();

EndPrimitive();

}

void createTriangleGeometry(in vec4 v, in float f_size, in mat4 orientation)

{

gl_Position = v; EmitVertex(); //n1

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n2

gl_Position = v; EmitVertex(); //n3

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size/4, f_size/2, 0., 0.)); EmitVertex(); //n4

gl_Position = v; EmitVertex(); //n5

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size/2, 0., 0., 0.)); EmitVertex(); //n6

gl_Position = v; EmitVertex(); //n7

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, -f_size, 0., 0.)); EmitVertex(); //n8

gl_Position = v; EmitVertex(); //n9

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., -f_size, 0., 0.)); EmitVertex(); //n10

gl_Position = v; EmitVertex(); //n11

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, -f_size, 0., 0.)); EmitVertex(); //n12

gl_Position = v; EmitVertex(); //n13

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size/2, 0., 0., 0.)); EmitVertex(); //n14

gl_Position = v; EmitVertex(); //n15

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size/4, f_size/2, 0., 0.)); EmitVertex(); //n16

gl_Position = v; EmitVertex(); //n17

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n18

gl_Position = v; EmitVertex(); //n19

EndPrimitive();

}

void createRectangleGeometry(in vec4 v, in float f_size, in mat4 orientation)

{

gl_Position = v; EmitVertex(); //n1

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n2

gl_Position = v; EmitVertex(); //n3

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, f_size, 0., 0.)); EmitVertex(); //n4

gl_Position = v; EmitVertex(); //n5

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, 0., 0., 0.)); EmitVertex(); //n6

gl_Position = v; EmitVertex(); //n7

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(f_size, -f_size, 0., 0.)); EmitVertex(); //n8

gl_Position = v; EmitVertex(); //n9

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., -f_size, 0., 0.)); EmitVertex(); //n10

gl_Position = v; EmitVertex(); //n11

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, -f_size, 0., 0.)); EmitVertex(); //n12

gl_Position = v; EmitVertex(); //n13

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, 0., 0., 0.)); EmitVertex(); //n14

gl_Position = v; EmitVertex(); //n15

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(-f_size, f_size, 0., 0.)); EmitVertex(); //n16

gl_Position = v; EmitVertex(); //n17

gl_Position = v + (gl_ModelViewProjectionMatrix * vec4(0., f_size, 0., 0.)); EmitVertex(); //n18

gl_Position = v; EmitVertex(); //n19

EndPrimitive();

}

in vec4 v_colorVS[];

in float f_size[];

in float f_style[];

in float f_dip[];

in float f_azimuth[];

out vec4 v_color_out;

void main(void)

{

v_color_out = v_colorVS[0];

vec4 v = gl_PositionIn[0];

// Create the orientation matrix

mat4 dip_rot = mat4( 1., 0., 0., 0.,

0., cos(f_dip[0]), -sin(f_dip[0]), 0.,

0., sin(f_dip[0]), cos(f_dip[0]), 0.,

0., 0., 0., 1.);

mat4 azimuth_rot = mat4( cos(f_azimuth[0]), -sin(f_azimuth[0]), 0., 0.,

sin(f_azimuth[0]), cos(f_azimuth[0]), 0., 0.,

0., 0., 1., 0.,

0., 0., 0., 1.);

mat4 orientation = matrixCompMult(dip_rot,azimuth_rot);

// Create the marker geometry

createCircleGeometry(v,f_size[0],orientation);

//createRectangleGeometry(v,f_size[0],orientation);

//createTriangleGeometry(v,f_size[0],orientation);

}