I am using opengl es 2.0, how do if ind the hit point on the object which was parallel with the camera.

Setup for my camera:

App app = App.getInstance();

app.setWidth(width);

app.setHeight(height);

float widthDP = width;

float heightDP = height;

float ratio = widthDP / heightDP ;

mShader = new SimpleShader();

Polygon poly = Polygon.Builder()

.addVertex(new Point(widthDP*6,heightDP*2))

.addVertex(new Point(widthDP*6, 0))

.addVertex(new Point(0, heightDP*2))

.addVertex(new Point(0, 0)).build();

Environment environment = Environment.getInstance();

environment.setPolgyon(poly);

environment.setScreenSize((int)widthDP, (int)heightDP);

Camera camera = Camera.getInstance();

camera.setShader(mShader);

camera.setEye(new Point3D(widthDP*2,heightDP, -heightDP));

camera.setLook(new Point3D(widthDP*2,heightDP,0));

camera.setUp(new Point3D(0,1,0));

environment.setCamera(camera);

Matrix.frustumM(camera.getProjectionMatrix(), 0, -ratio, ratio, -1, 1, 1, 1000);

This is the code I followed from the link: schabby.de/picking-opengl-ray-tracing/

App app = App.getInstance();

Vector3D lookAt = new Vector3D(look.x, look.y, look.z);

Vector3D position = new Vector3D(eye.x, eye.y, eye.z);

Vector3D up = new Vector3D(this.up.x, this.up.y, this.up.z);

Vector3D view = Vector3D.sub(lookAt, position);

view.normalize();

Vector3D h = view.cross(up);

h.normalize();

Vector3D v = h.cross(view);

v.normalize();

float rad = (float) (45.0f * Math.PI / 180.0f);

float vLength = (float) Math.tan( rad / 2 ) * 1;

float hLength = vLength * (app.getWidth() / app.getHeight());

v.mult(vLength);

h.mult(hLength);

//point.x = app.getWidth() - point.x;

//point.y = app.getHeight() - point.y;

point.x -= app.getWidth()/2;

point.y -= app.getHeight()/2;

point.x *= -1;

point.y *= -1;

Log.w("point", "Width x="+point.x +" y="+point.y);

point.x /= app.getWidth();

point.y /= app.getHeight();

view.mult(1);

h.mult(point.x);

v.mult(point.y);

view.add(h);

view.add(v);

Vector3D pos = Vector3D.add(position, view);

Vector3D dir = Vector3D.sub(pos, position);

float s = -1*pos.z / dir.z;

float[] newPoint = new float[2];

newPoint[0] = pos.x + dir.x *s;

newPoint[1] = pos.y + dir.y *s;

The two lines below, i did that because the screen coordinates starting from the center of the screen and towards left as a positive x-axis and upwards as positive for y-axis. whereas towards the right was negative and toward bottom is negative.

point.x *= -1;

point.y *= -1; ]]>

I'm in need of testing if an axis oriented bounding box collides with a triangle (set of triangles as a terrain), and if it does - in which point. I found few algorithms on the internet, but I can't determine the intersection point, which is essential for me here.

Is there an algorithm to achieve what I need? Or maybe is there some method that suits this task better?

Thanks. ]]>

<www.opengl.org/wiki/GLAPI/glViewport>

xw = (xnd + 1) (width / 2) + x;

yw = (ynd + 1) (height / 2) + y;

First test: Assume x=0 and width=800, then the window coordinates go from 0 to 799.

xnd = 1 should result in the rightmost pixel 799.

xw ( 1 ) = ( 1 + 1 ) * 800 / 2 + 0 = 800; And not 799.

I derivated the formula for normalized device to window coordinates and came to a slightly different result

to replace "width" by "(width - 1)":

xw = (xnd + 1) ((width - 1) / 2) + x;

yw = (ynd + 1) ((height - 1) / 2) + y;

Here my derivation for glViewport( x, y, width, height ):

So the rectangle is from (x) to (x + width - 1), and from (y) to (y + height - 1).

Example: glViewport( 400, 200, 800, 600 ) has a rectangle from x: 400 to 1199, and y: 200 to 799.

Formula for x:

xw - x = xnd * a + b; // Linear equation, resolve a and b.

1. xnd = -1, and xw = x:

x - x = -1 * a + b; -> a = b;

2. xnd = +1, and xw = x + width - 1:

x + width - 1 - x = 1 * a + b; -> width - 1 = 2 a; -> a = ( width - 1 ) / 2;

Insert in formula for x:

xw - x = xnd * (width - 1) / 2 + (width - 1) / 2;

xw = ( xnd + 1 ) * (( width - 1 ) / 2 ) + x;

Test:

1. xnd = -1: xw = ( -1 + 1 ) * (( width - 1 ) / 2 ) + x = x; -> ok, 400 by the example.

2. xnd = +1: xw = ( 1 + 1 ) * (( width - 1 ) / 2 ) + x = width - 1 + x; -> ok, 1199 by the example.

Analogical for y. ]]>

If I want to rotate a mesh around a point (x,y,z) and the axis of the rotation is oriented by the vertex (vx,vy,vz), how can I get the matrix of this rotation, please? I use GLM in cas there is a function that can perform that directly.

Thanks

Cathy L. ]]>

If I want (using GLM) to perform the rotation of alpha radians of a mesh around the point (x,y,z) and with an axis orientation (of the rotation) is given by a vector (vx,vy,vz), how do I get the matrix for that, please?

Thanks a lot

Cathy L. ]]>

Any good implementation?

Thanks. ]]>

I have been moving from intermediate mode to to full opengl 3+, it has gone well but I still have a couple of issues to solve. One of the biggest I have is the move to having 4x4 transformation matrix.

I understand where the translation bits go, the rotation bits and the scaling bits go but I am a little unsure as to how best to handle the multiplication. I have a single 4x4 matrix with the scaling, rotation and translation all applied, lets say I have a bone skeleton and i want to work out the initial positions (So I need to multiply in a recursive way). When I multiply this out to work out the bones final positions I "should" (in my mind) just be able to multiply the 4x4 transformations but I don't think this is right.

The scale components effect the rotation components so I am thinking should I actually keep the scale, rotation and translation components separate and multiply these like I did before and only combine to a 4x4 at the very end when I have the final transformation, or am I talking rubbish and the 4x4 matrix multiplication should all work and there is a bug else where in my code? (I can't get my objects to draw correctly as they were before so there is definitely a problem somewhere).

To give you are idea of what I did before, this is the pseudo code for the transformation code I had before (scale, rotation and translation kept as separate items)

newXXX = the result of the multiplication

currentXXX = the current transformation values

toMultiplyXXX = the transformation to multiplied with

(newXXX = currentXXX * toMultiplyXXX)

newPosition = (currentRotation * toMultiplyPosition) + currentPosition

newRotation = currentRotation * toMultiplyRotation

newScale = currentScale * toMultipleScale ]]>