Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR for sphere_intersection branch #1064

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions plugins/mmstd_moldyn/Shaders/sphere/vertex_spheretouchplane.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
vec3 testPos;
vec4 projPos;

#if 0
// projected camera vector
vec3 c2 = vec3(dot(camPos.xyz, camRight), dot(camPos.xyz, camUp), dot(camPos.xyz, camIn));

Expand Down Expand Up @@ -77,3 +78,53 @@
testPos = objPos.xyz - camIn * rad;
projPos = MVP * vec4(testPos, 1.0);
projPos /= projPos.w;
#else

vec3 base_vec = (-camPos.xyz);
float bv = length(base_vec);

//vec3 cc = vec3(dot(base_vec, camRight), dot(base_vec, camUp), dot(base_vec, camIn));

//vec3 hv = normalize(-cc.z*camRight+cc.x*camIn);
//vec3 uv = normalize(cross(hv, base_vec));

vec3 in_v = normalize(base_vec);
vec3 up = normalize(cross(in_v, camRight));
vec3 right = normalize(cross(in_v, up));
up = normalize(cross(in_v, right));

float pe = squarRad/bv;
float h2 = squarRad-pe*pe;
float ha = sqrt(h2);
//float qu = bv-pe;
//float x = ha/qu*(qu-rad+pe);

vec3 plane_base = objPos.xyz - in_v*pe;
vec3 corner_0 = plane_base-right*ha-up*ha;
vec3 corner_1 = plane_base+right*ha-up*ha;
vec3 corner_2 = plane_base+right*ha+up*ha;
vec3 corner_3 = plane_base-right*ha+up*ha;

projPos=MVP*vec4(corner_0,1.0);
projPos/=projPos.w;
mins = projPos.xy;
maxs = projPos.xy;

projPos=MVP*vec4(corner_1,1.0);
projPos/=projPos.w;
mins = min(mins, projPos.xy);
maxs = max(maxs, projPos.xy);

projPos=MVP*vec4(corner_2,1.0);
projPos/=projPos.w;
mins = min(mins, projPos.xy);
maxs = max(maxs, projPos.xy);

projPos=MVP*vec4(corner_3,1.0);
projPos/=projPos.w;
mins = min(mins, projPos.xy);
maxs = max(maxs, projPos.xy);

projPos=MVP*vec4(objPos.xyz - camIn*rad,1.0);
projPos/=projPos.w;
#endif