Blitz logo

Blitz Support :

From: Toby Walsh (twalsh_at_[hidden])
Date: 2004-10-25 20:48:03


Hi Dirk,

Although I'm OpenGL through and through, I'm tempted to switch to DirectX's
math routines for that sort of stuff. My app is more scientific than
graphical, but I do use some transformations. Here's some example code for
a camera class:

// Move the camera forward.
// Returns: void.
void CCamera::MoveForward()
{
         Vector f(centre_ - eye_);
         Normalise(f);
         f *= dist_;
         eye_ += f;
         centre_ += f;
}

// Move the camera left.
// Returns: void.
void CCamera::MoveLeft()
{
         Vector s(Cross((Vector)(centre_ - eye_), up_));
         Normalise(s);
         s *= dist_;
         eye_ -= s;
         centre_ -= s;
}

// Transforms the screen according to the camera orientation.
// Returns: void.
void CCamera::View()
{
         glLoadIdentity();
         gluLookAt(eye_(0), eye_(1), eye_(2), centre_(0), centre_(1),
centre_(2), up_(0), up_(1), up_(2));
}

centre_, eye_ and up_ are member vars representing the camera position,
eye vector and up vector respectively. Vector is typedef'd
blitz::Array<float, 1>. Cross() and Normalise() do what you'd expect and
I've got those in simple LinearAlgebra.cpp/hpp files. The LinearAlgebra
stuff calculates anything 4x4 or less explicitly and anything more
algorithmically. It's also got Matrix/Matrix, Matrix/Vector, Vector/Matrix
multiplication, inverses, etc. A Matrix is obviously blitz::Array<float,
2>. Composition isn't a problem, although IIRC I do have to use explicit
casts sometimes (like in the first line of MoveLeft) otherwise VC++ 7.1
gives me something like incompatible type errors. This camera class is
nowhere near a bottleneck for me, so it suffices.

Toby

At 11:53 AM 10/25/2004 +0200, you wrote:
>Thanx for the answer.
>
>What about the affine transformations? What would be the most effective
>solution to define some basic transformation matrices that than can
>conviniently be composed?
>
>-Dirk
>
>
>----- Original Message ----- From: "Toby Walsh" <twalsh_at_[hidden]>
>To: "Support list for Blitz++" <blitz-support_at_[hidden]>
>Sent: Monday, October 25, 2004 5:51 AM
>Subject: Re: [Blitz-support] Blitz++ in graphic application
>
>
>>Hi Dirk,
>>
>>(1) I used Blitz++ for graphical stuff. There's no problem. I did stuff
>>like vertices and indices stored in Arrays. You can then pass them to
>>e.g. glVertexPointer etc by using the "data()" member function.
>>
>>(2) I did the math myself.
>>
>>(3) If you do use Blitz++ stuff to store all your data, you can wrap the
>>data like I did - I typedef'd Array<..., 2> as Matrix (with the type as a
>>suffix on Matrix like OpenGL does) and Array<..., 1> as Vector. Then you
>>can change data representations later if you like.
>>
>>Toby
>>
>>
>>At 03:19 PM 10/23/2004 +0200, you wrote:
>>>Hi,
>>>
>>>in the coming semester I have to write a character animation system for
>>>a small student project. I am wondering if I can use Blitz++ ( mainly
>>>TinyVector and TinyMatrix ) for the affine transformations.
>>>
>>>1.) Did anybody used Blitz++ with OpenGL or DirectX? Are there any
>>>problems passing a TinyMatrix<float, 4, 4> to one of the APIs?
>>>
>>>2.) Does Blitz++ support affine transformations? If not - how shall I
>>>implement the basic transformations ( scale, rotation, translations, ...
>>>) such that they can be concatenated efficently and can be written like
>>>below. E. g.
>>>
>>>TinyMatrix<float, 4, 4> transform = translation( 0, 0, -3 ) * rotation_y
>>>( 45 ) * translation( 0, 0, 3 );
>>>
>>>Can I write wrapper functions to implement the basic transformations or
>>>should I better use the ListInitializer like in the transform example?
>>>
>>>3. ) I would be also nice to have support for some geometric objects
>>>like lines, planes, boxes and so on? Would it be a good idea to
>>>implement them on top of Blitz++? E.g.
>>>
>>>struct BBox
>>>{
>>> TinyVector3<float, 3> min, max;
>>>}
>>>
>>>So the question is if Blitz++ is suited for a task like mine or if
>>>should implement a small math library own my own that suits my needs.
>>>
>>>-Dirk
>>>
>>>
>>>_______________________________________________
>>>Blitz-support mailing list
>>>Blitz-support_at_[hidden]
>>>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>>
>>Toby Walsh
>>PhD Student
>>School of Mechanical Engineering
>>The University of Western Australia
>>CRICOS provider no. 00126G
>>Phone: +61 8 9488 3937
>>Email: twalsh_at_[hidden]
>>
>>
>>_______________________________________________
>>Blitz-support mailing list
>>Blitz-support_at_[hidden]
>>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support
>
>_______________________________________________
>Blitz-support mailing list
>Blitz-support_at_[hidden]
>http://www.oonumerics.org/mailman/listinfo.cgi/blitz-support

Toby Walsh
PhD Student
School of Mechanical Engineering
The University of Western Australia
CRICOS provider no. 00126G
Phone: +61 8 9488 3937
Email: twalsh_at_[hidden]