Log in or register to post comments

Orthographic projection - How to?

May 21, 2012 - 4:13am #1

Hi all,

I started working on ImageTargets example and using OpenGL 1.1 I am rendering rectangular planes on the scene. And I want to get these rectangles' screen coordinates, so that I can check if they are overlapping or not.

My method to do this on a regular java - gles code is : get modelview matrix, get projection matrix, get viewport and using gluProject, project the 3D opengl coordinates into 2D screen coordinates. However, I am coding on NDK right now and it doesn't support GLU. Then I decided to use QCAR functions.
I changed my method to this: Get Camera Calibration from QCAR::CameraDevice, get pose from current trackable object, and project a 3D point using projectPoint function into camera coordinates. I know that I need to convert camera coordinates into screen coordinates too... Am I on the right track? :confused:

This path led me to another problem. I wanted to check to see if I'm doing right or wrong by rendering the 2D coordinates using orthographic projection on the scene. I tried to do some basic point rendering using orthographic projection, but couldn't see anything on the screen :( Here is the part where I try to do this ( inside renderFrame method of ImageTargets.cpp after I render the rectangles in 3D ):

  

glPushMatrix();
glMatrixMode(GL_PROJECTION);
glOrthof(0, screenWidth, 0, screenHeight, -1, 1); 

glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glPointSize(10.0);
glColor4f(0.0, 1.0, 0.0, 1.0);
glTranslatef(100, 100, 0);
glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*) &tmpPoint[0]);
glDrawArrays(GL_POINTS, 0, 1);
glPopMatrix();

How can I render 2D on top of the Vuforia rendering pipeline? The answer can be useful for implementing HUD for any Vuforia app.

Any help would be appreciated, thanks

Orthographic projection - How to?

August 14, 2013 - 1:17am #8

Hi AlessandroB,

I already get the result below, I have afollow up question:

1. How to maintain the size of video covering 80% display in the phone screen and never resize?

2. Lastly, continuous play of video even there is no image target.

AttachmentSize
Image icon logged-videoplayback.png196.63 KB

Orthographic projection - How to?

August 14, 2013 - 1:10am #7

That's just a C++ function; you should copy it before the _renderFrame() function

Orthographic projection - How to?

August 14, 2013 - 12:30am #6

Sir AlessandroB,

where in renderframe to insert this code:

void setIdentity(float *matrix)

Orthographic projection - How to?

August 13, 2013 - 11:57pm #5
void setIdentity(float *matrix)
{
int i, j;
for (i = 0; i < 4; i++)
    {
        for (j = 0; j < 4; j++)
            matrix[i * 4 + j] = (i == j ? 1.0f : 0.0f);
    }
}

Orthographic projection - How to?

August 13, 2013 - 8:12pm #4

Uhmm willyou helpme where to set the  projection matrix to identity matrix ?

Orthographic projection - How to?

August 13, 2013 - 8:12pm #3

Uhmm willyou helpme where to set the  projection matrix to identity matrix ?

Re: Orthographic projection - How to?

May 28, 2012 - 11:01am #2

Hi all!
I couldn't get any answers to my questions from the community, but in the meantime I was working on them and I solved them! :) Hope this helps to some people, too...

Let me start with my last question:

Quote:

How can I render 2D on top of the Vuforia rendering pipeline?

Sometimes you can forget really small stuff to put in the code... What was missing in the code block that I posted was a glLoadIdentity(); right after glMatrixMode(GL_PROJECTION)! Since I didn't set the projection matrix to identity matrix first, glOrtho command was multiplying camera projection matrix with its projection matrix. That's why I couldn't render in 2D. Now it works solid.

Back to the first question about projecting 3D objects onto view plane and rendering them on 2D... I was on the right track! But don't forget to project the point coordinates from camera coordinate system into the screen coordinate system. Vuforia captures the video and scales it according to the screen size to make the video fullscreen. Note that it maintains the aspect ratio of the video. In my case, the captured video size is 640x480, screen size is 800x480, that's why the scaled video size is 800x600. Vuforia centers the midpoint of this scaled video to the screen coordinate system. In my case the height difference is 120, thus there is 60px unseen part of the video on the top and bottom of the screen. Here's the code for this:

	
QCAR::Vec2F point_2D = 
   QCAR::Tool::projectPoint(cameraCalibration, pose, point_3D); // projects onto the camera coordinate system  
// divide by scaleFactor to project to scaled-camera-coordinate system
point_2D.data[0] *= ((float)1.0/scaleFactor.data[0]); //scaleFactor.x= 640/800
point_2D.data[1] *= ((float)1.0/scaleFactor.data[1]);  // scaleFactor.y = 480/600;
point_2D.data[1] = 600-point_2D.data[1];

glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(0, 800 0, 600, -1 , 1); // scaled video size is 800x600
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();

glPointSize(10.0);
glColor4f(0.0, 1.0, 0.0, 1.0);
glVertexPointer(2, GL_FLOAT, 0, (const GLvoid*) &point_2D[0]);
glDrawArrays(GL_POINTS, 0, 1);



best,

Log in or register to post comments