vendredi 27 décembre 2013

OpenGL with Eigen: re-implementing perspective and lookat

I am looking at OpenGL 3.3 and gluperspective and glulookat are deprecated in core 3.3

You can find them in GLM (as functions perspective and lookat)
but I am using Eigen, and after a long reflexion with myself, I decided to stay with Eigen.

I made a version of perspective and lookat for Eigen:

#include "Eigen/Core"

template<class T>
Eigen::Matrix<T,4,4> perspective
    double fovy,
    double aspect,
    double zNear,
    double zFar
    typedef Eigen::Matrix<T,4,4> Matrix4;

    assert(aspect > 0);
    assert(zFar > zNear);

    double radf = Math::degToRad(fovy);

    double tanHalfFovy = tan(radf / 2.0);
    Matrix4 res = Matrix4::Zero();
    res(0,0) = 1.0 / (aspect * tanHalfFovy);
    res(1,1) = 1.0 / (tanHalfFovy);
    res(2,2) = - (zFar + zNear) / (zFar - zNear);
    res(3,2) = - 1.0;
    res(2,3) = - (2.0 * zFar * zNear) / (zFar - zNear);
    return res;

template<class T>
Eigen::Matrix<T,4,4> lookAt
    Eigen::Matrix<T,3,1> const & eye,
    Eigen::Matrix<T,3,1> const & center,
    Eigen::Matrix<T,3,1> const & up
    typedef Eigen::Matrix<T,4,4> Matrix4;
    typedef Eigen::Matrix<T,3,1> Vector3;

    Vector3 f = (center - eye).normalized();
    Vector3 u = up.normalized();
    Vector3 s = f.cross(u).normalized();
    u = s.cross(f);

    Matrix4 res;
    res <<  s.x(),s.y(),s.z(),,

    return res;

and easy to use:


typedef Eigen::Matrix4f Matrix4;
typedef Eigen::Vector3f Vector3;

float fovy = ...;
float ratio = ...;
float near_plan = ...;
float far_plan = ...;

Matrix4 projectionMatrix = perspective<Matrix4::Scalar>(

Vector3 eye, center, eyeUp;
... init code ...

Matrix4 cameraMatrix = lookAt( eye, center, eyeUp );

if you are using OpenGL 2.1 then you can use them as:


    glLoadMatrixf( );



Hope it will be useful for you as well, let me know if it was.

samedi 28 septembre 2013

python install without admin rights


I started recently some programming in python but I needed to install it first on a windows machine without admin rights.... but how to do it, many forums came to the "portable python" and it works, it is just outdated 3.2.x, and as a good programmer (sigh) I wanted to have the latest of course.

The procedure is actually very simple, just download the msi installer from and type the command:
> C:\development\apps>msiexec /a python-3.3.2.msi /qb TARGETDIR=C:\development\apps\python33

then python will be in the directory specified by TARGETDIR.

enjoy python!

but hold on a minute ... what about an editor?  komodo-edit for instance?

download and type:
> msiexec /a Komodo-Edit-8.5.0-13638.msi /qb TARGETDIR=C:\development\Apps\Komodo-Edit

enjoy python even more!

(as usual, let me know if it has been useful for you.)

dimanche 8 septembre 2013

Apex and CSS


I am working with Oracle / Apex and I had the css using images on a different server. As these links were http and we had to work on https, IE 8 didn't stop to display security message (https security compromised by http calls), so we had to fix the css...

but how? the images should become local in the workspace images but how to reference them?

Unfortunately it doesn't work because Apex doesn't make the substitution, but then are we .... stuck?

I thought that it wouldn't be possible to do anything but I found CSSEMBED

the jar file can be found in the link above but I repeat it:
wonderful, just had to execute this command:
java -jar cssembed-x.y.z.jar -o output_filename.css input_filename.css
and my css has now the images inlined. just wonderful.

Thanks Nicholas C. Zakas for this great product.

Happy coding.