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(),-s.dot(eye),
            u.x(),u.y(),u.z(),-u.dot(eye),
            -f.x(),-f.y(),-f.z(),f.dot(eye),
            0,0,0,1;

    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>(
    fovy,
    ratio,
    near_plan,
    far_plan
);

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:

    glMatrixMode(GL_PROJECTION);
    glLoadIdentity();

    glLoadMatrixf( projectionMatrix.data() );

and

    glMatrixMode(GL_MODELVIEW);
    glLoadIdentity();
    glLoadMatrixf(cameraMatrix.data());


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

samedi 28 septembre 2013

python install without admin rights

Hello,

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 http://www.python.org/getit/ 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 http://www.activestate.com/komodo-edit/downloads 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

Hello,

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?
#WORKSPACE_IMAGES#my_image.jpg

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.

samedi 8 septembre 2012

using Eigen

Hello,

Today I took some time to replace my own (vector) math library by Eigen.
This library is great and fast. I could replace my own lib in my software (3d opengl and math calculation) in few hours only.
(I still use the "double" type because it provides better precision and I didn't see any speed improvement using float)

PS: if you see a linkage issue with Eigen and you are using cross or dot, then just include the geometry header: #include <Eigen/Geometry>

Hope it will be useful for you.

Happy coding.




dimanche 12 août 2012

compiling boost with clang mac os x

Here is the command to compile boost on mac os x with clang:

> ./bootstrap.sh
> ./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++"

however boost 1.50 has issue with the signal lib,
I downloaded trunk, everything ok so far.

and to install:

> ./b2 toolset=clang cxxflags="-stdlib=libc++" linkflags="-stdlib=libc++" install

enjoy boost.

dimanche 5 août 2012

fastcgi with apache on mac os x lion

Hi,

First of all, I had many issues with apache to make it running. It does not start well from the preferences. Google it to find some workarounds, but none of them really worked for me.
Even sometimes, it indicates as not running but it is :-/

just few tips about apache on max os x (lion):

> sudo apachectl stop
to stop apache

> sudo apachectl start
to start apache

> sudo apachectl -t
to check what was wrong

> cat /var/log/apache2/error_log
to check the error log


1. First we would need to get the fastcgi library:
http://www.fastcgi.com/dist/fcgi.tar.gz

unzip it somewhere and go the the unzipped folder.
> ./configure
> make
> sudo make install
as an alternative for clang++ with c++11 and libc++ (with c++11 support)
>  CC="clang" CXX="clang++" CFLAGS="-stdlib=libc++" CXXFLAGS="-stdlib=libc++" ./configure

... easy for now :-)

2. Now we would need the apache module
http://www.fastcgi.com/dist/mod_fastcgi-current.tar.gz

unzip it somewhere and go the the unzipped folder.
> sudo apxs -n mod_fastcgi -i -a -c mod_fastcgi.c fcgi_buf.c fcgi_config.c fcgi_pm.c fcgi_protocol.c fcgi_util.c

it will compile and install the mod_fastcgi for apache.

3. To Configure apache, let's edit the config file:
> sudo nano /private/etc/apache2/httpd.conf

add the line:
LoadModule fastcgi_module libexec/apache2/mod_fastcgi.so

and at the end of the file:

<IfModule mod_fastcgi.c>
FastCgiIpcDir /tmp/fcgi_ipc/
AddHandler fastcgi-script .fcgi
</IfModule>
now CTRL+O to save the file
CTRL+X to quit

4. let's create the folder /tmp/fcgi_ipc
> sudo mkdir /tmp/fcgi_ipc
> sudo chmod 777 /tmp/fcgi_ipc
5. it should be ready now, let's test it.
so just take an example from the lib http://www.fastcgi.com/dist/fcgi.tar.gz in the folder "examples"

just take "echo.c", put it on a folder then
> gcc echo.c -lfcgi -o echo.fcgi
> sudo cp echo.fcgi /Library/WebServer/CGI-Executables/
now you can access it with your browser with the url:
http://127.0.0.1/cgi-bin/echo.fcgi

Hope it will be useful for you, happy coding!


lundi 30 juillet 2012

OpenCV and CLang / C++ 2011 on mac os x


OpenCV cannot be used in a project using C++11.
I am on mac os x and the new default compiler is CLang.

The issue is that the stdlib for c++11 is "libc++ with c++11 support" but this is not the default one.

solution: compiling OpenCV with CLang and libc++

so how to do it?

cmake ../  -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang++ -DCMAKE_CXX_FLAGS="-stdlib=libc++"

but there is one (small) issue:
OpenCV-2.4.2/modules/ts/include/opencv2/ts/ts_gtest.h uses std:tr1:tuple and it will generate an compiler error.

solution: edit this file and add on the first line:
#define GTEST_USE_OWN_TR1_TUPLE 1

then it will work ! you should be able to use C++2011 in your project using OpenCV on mac os x

BTW my opencv version is 2.4.2