Archived

This topic is now archived and is closed to further replies.

pt

Own math lib - to write, or not to write...

Recommended Posts

Elo all I''ve just started writing my first 3D-math library (I''m absolutly new to 3D graphics) but I wonder if this is a good idea. I have some math background about matricies, vectors etc., and I know that graphical APIs (i.e. ogl and dx) have their own helper functions for 3D math. I already have basic operations (multiplications, rotations etc.) in my lib and now it''s time for projection matricies, world transformations and so on. The reason for writing such a lib is api independence... I was thinking about future improvements like translating lib functions to asm (using SIMD instructions). so, my questions 1) is it worth to bother writing own lib? 2) what about efficiency in comparison to dx/ogl implementations? 3) what about api independence? and finally how do you do your math? p.s. excuse my english, since it''s definitely not my native language, but I''m doing my best

Share this post


Link to post
Share on other sites
quote:
1) is it worth to bother writing own lib?


Depending on how specialized your application is, it might be. On the other hand, there are a lot of really good math libraries out there; do a web search.

quote:
2) what about efficiency in comparison to dx/ogl implementations?


For what DX/OGL do (linear algebra) you''re unlikely to beat them. But there are a lot of things you shouldn''t look to those APIs for--collision detection, visibility culling, etc.

quote:
3) what about api independence?


If you''re going for API independence, math is the least of your worries. There just isn''t much difference between different matrix classes. That said, if you must have it, you''re better off not using DX (for obvious reasons).

quote:
And finally how do you do your math?


I''ve whipped out matrix and vector classes that work very well for what I need them for. Beyond that, pencil, paper, and my trusty TI-86.

quote:
p.s. excuse my english, since it''s definitely not my native language, but I''m doing my best


You talk better than a lot of the native english speakers we see around here.

Share this post


Link to post
Share on other sites
hehe, that was my first post

Thx very much for answer.

I''ve already found some math libs on the net, but I think writing and using my own would be a good practice, at least at the beginning. I know it sounds like "I''m gonna reinvent the wheel", but I''m sure this approach would give me better theoretical background for writing extra_cool_mega_quake_3000 in near future :D

Share this post


Link to post
Share on other sites
Write your own...even if there not as good as the DX suplied ones, at least you know how it all works and changing it to the DX / OGL implementations shouldn''t be too hard as long as you designed it well.

Share this post


Link to post
Share on other sites
Well, I already have all math stuff. Now I have to understand this freaky render pipe. It'd be much easier to just take D3DXMatrixLookAtRH and stuff...

btw. maybe someone has some nice examples about those camera, perspective matricies etc.? I've collected a bunch of tutors from the net (I've probably seen all arts from gamedev, flipcode, gametutorials etc.), and still all this stuff seems a bit messy for me.

In particular I'm not sure how to create projection and view matricies. In few arts i found just formulas, but without a good explanation. So if you have some nice step-by-step guides which might clear this up...

My super_cool_doom_3000 is coming closer, I feel it

[edited by - pt on July 16, 2002 2:33:25 PM]

Share this post


Link to post
Share on other sites
Yea, i think is great, i am beginer, but i have the curiosity for this things, for all i like try to understand all i use, including the api of win 32 how it can "administrar" the applications and send messages, maibe i later with some more experience i try to make a os, only for test me "conclusion" or opinions about that, but for the moment i am interesting in how i can make a complete own library, including, graphics (2d,3d), sound(maibe 3d sound), control of the mouse, keyboard, and why not comunication by inet.

You see??, i dont have good english, i have some grasp in a variety of languages, but i consider my self beginner.

OK, is a nice project, yea come, lets rock .

Congratulations.

Sorry for me bad english, cya.

Share this post


Link to post
Share on other sites
(Sorry if I repeat anyone but these are just my opinions)

I recommend that you write at least one good math library by yourself to start off with, it''ll allow you to understand the whole stuff better. Even go as far as trying to optimise the larger functions (such as matrix multiplication, and vector array transformation) as that will give you the understanding of how a processor will deal with a particular situation.

But remember not to go overboard, IMO a simple "vector" class or set of vector manipulating functions and the same for a matrix should be enough (just do a 4x4 matrix, since its the most common) and then once you''ve got those done and the bugs ironed out you can do more "exotic" stuff that deals with planes, 3x3, 3x2, 6x6 matrices and stuff.

(BTW has anyone ever found a use for 6x6 matrices?)

Dæmin
(Dominik Grabiec)
dominik.grabiec@student.adelaide.edu.au

Share this post


Link to post
Share on other sites
As long as your matrix class has a good number of helper member functions, setting up transformations should be as easy as calling a few matrix member functions, and multiply.

However, writing your own library to start is a great learning experience.

quote:
(BTW has anyone ever found a use for 6x6 matrices?)

5-dimensional mathmatics Don''t tell me you''ve never done that before!

Share this post


Link to post
Share on other sites
You can use matrices of dimension higher than four in other places. If you ever do work with physical stuff (that noisy, dirty real world thing), then you might wind up writing state transition equations that involve more than four variables. This is especially true in kalman filters, where you might be multiplying matrices of dimension ten (or higher; I'm using 16x16, but trying to slim it down...). I ended up writing a templated matrix class, which isn't too optimal, but it's really easy to work with. This is nice for variable sized matrices, since it's a real pain to have to write a seperate class for each possible dimension of matrix...

EDIT: typo...

[edited by - tsuraan on July 18, 2002 9:52:56 AM]

Share this post


Link to post
Share on other sites