Problem with CCCamera->setEyeXYZ ()

Problem with CCCamera->setEyeXYZ ()
0.0 0

#1

Hi, first, sorry for my bad english.

I’m using “CCCamera->setEyeXYZ ()” for doing a pseudo-3d perspective.
The problem come when I try to position objects in this place.
How I can turn a screen point to its equivalent in the pseudo-3d perspective?

Example:
In “eyexyz.png”, the sprite without setEyeXYZ () effect.
In “eyexyz2.png” with the setEyeXYZ (x,–0.0000001f,z) pseudo-3d effect.

I need the algorithm to calculate the position of any point inside the texture.
The upper left corner is (0,149) (anchor [0,1]).
In the perspective this point is (61,126).

I’ve tried a lot of things, but none solved the problem.

eyexyz.png (7.2 KB)

eyexyz2.png (14.3 KB)

#2

Using GluLookat code:

``````void Transform(float &xx, float &yy, float &zz,  // Coordinates to transform
float fEyeX, float fEyeY, float fEyeZ, // lookAtXYZ
float fCenterX, float fCenterY, float fCenterZ,
float fUpX, float fUpY, float fUpZ)
{

GLfloat x[3], y[3], z[3];
GLfloat mag;
// Make rotation matrix
// Z vector
z[0] = fEyeX - fCenterX;
z[1] = fEyeY - fCenterY;
z[2] = fEyeZ - fCenterZ;
mag = (float)sqrtf(z[0] * z[0] + z[1] * z[1] + z[2] * z[2]);
if (mag) {
z[0] /= mag;
z[1] /= mag;
z[2] /= mag;
}
// Y vector
y[0] = fUpX;
y[1] = fUpY;
y[2] = fUpZ;
// X vector = Y cross Z
x[0] = y[1] * z[2] - y[2] * z[1];
x[1] = -y[0] * z[2] + y[2] * z[0];
x[2] = y[0] * z[1] - y[1] * z[0];
// Recompute Y = Z cross X
y[0] = z[1] * x[2] - z[2] * x[1];
y[1] = -z[0] * x[2] + z[2] * x[0];
y[2] = z[0] * x[1] - z[1] * x[0];
/* cross product gives area of parallelogram, which is < 1.0 for
* non-perpendicular unit-length vectors; so normalize x, y here
*/
mag = (float)sqrtf(x[0] * x[0] + x[1] * x[1] + x[2] * x[2]);
if (mag) {
x[0] /= mag;
x[1] /= mag;
x[2] /= mag;
}
mag = (float)sqrtf(y[0] * y[0] + y[1] * y[1] + y[2] * y[2]);
if (mag) {
y[0] /= mag;
y[1] /= mag;
y[2] /= mag;
}
// Now, calculate the new coordinates...
GLfloat cX = x[0]*xx + x[1]*yy + x[2]*zz;
GLfloat cY = y[0]*xx + y[1]*yy + y[2]*zz;
GLfloat cZ = z[0]*xx + z[1]*yy + z[2]*zz;
// This coordinates must be converted to 2D
// Xn = Xvcenter + (Xe/Ze · Vwidth)/(2·tan(θ/2))
// Yn = Yvcenter + (Ye/Ze · Vheight)/(2·tan(θ/2))
// TODO
float t1 = 1.5488305 * 2.f; // Inverse calculated
float t = tan (t1 / 2.f);
float angle = 2.f * t;
xx = (0.f / 2.f) + ((cX/cZ) * 480.f)/angle;
yy = (0.f / 2.f) + ((cY/cZ) * 320.f)/angle;
}
``````

What angle is θ???

I’ve tried inverse calculation, but when this angle works for “xx” is wrong to “yy”.
Maybe there are others errors…

#3

The best solution is use GluProject () sources

#4

Hey,
Sorry to resurrect an old thread -
glad you found a solution,

im in the exact same problem, mind sharing what to do with gluproject?
Thanks,
Dan