46
Support / Re: Screen size/shape & view area?
« on: August 17, 2015, 09:38:38 pm »
If i can get that along with the field of views i can extrapolate where the edge of the screen is at any distance.
This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
uniform [b]vec4[/b] specularColors[8];
precision mediump float;
uniform mat4 modelViewMatrix;
uniform mat4 modelViewProjectionMatrix;
attribute vec4 position;
attribute vec3 normal;
varying float fogthickness;
varying vec3 norm;
varying vec4 eye;
void main() {
vec3 n = normalize(modelViewMatrix * vec4(normal, 0.0)).xyz;
norm = n;
eye= -modelViewMatrix[3];
fogthickness = 1.0- dot(normalize(eye.xyz),n );
gl_Position = modelViewProjectionMatrix *position; //* vec4(position,1.0);
}
precision mediump float;
uniform vec3 atmosphereColour;
uniform vec4 specularColors[8];
uniform vec3 lightPositions[8];
varying vec3 norm;
varying vec4 eye;
varying float fogthickness;
void main() {
vec4 spec = vec4(0.0);
// normalize both input vectors
vec3 n = normalize(norm);
vec3 e = normalize(vec3(eye));
vec3 ligthDirection = normalize(lightPositions[0]);
float intensity = max(dot( n,ligthDirection), 0.0);
float shininess= 1.0;
// if the vertex is lit compute the specular color
if (intensity > 0.0) {
// compute the half vector
vec3 h = normalize(ligthDirection + e);
// compute the specular term into spec
float intSpec = max(dot(h,n), 0.0);
spec = specularColors[0] * pow(intSpec,shininess);
}
vec4 colorout = max(intensity * vec4(atmosphereColour,1) + spec, vec4(0.0));
gl_FragColor = vec4( colorout.xyz , fogthickness);
}
public static SimpleVector[] touch(MotionEvent e,FrameBuffer fb) {
int x = (int)e.getX();
int y = (int)e.getY();
SimpleVector raydirection = Interact2D.reproject2D3DWS(camera, fb, x, y).normalize();
SimpleVector cameraposition= new SimpleVector(camera.getPosition());
return sphereIntersect(cameraPosition, ray,object_positions,objectradius);
}
public static SimpleVector[] sphereIntersect(SimpleVector rayOrigin,SimpleVector rayDirection, SimpleVector sphereOrigin, float sphereRadius )
{
sphereOrigin.sub(rayOrigin);
double c = (double) sphereOrigin.length();
double v = (double) sphereOrigin.calcDot(rayDirection);
double d = sphereRadius * sphereRadius - (c * c - v * v);
if (d < 0.0) {
return new SimpleVector[0];
}
float distance = (float) (v - Math.sqrt(d));
rayDirection.scalarMul(distance);
SimpleVector r1 = new SimpleVector(rayDirection.calcAdd(rayOrigin));
return new SimpleVector[]{r1};
}