# 3D Without Using Vectors or Matrices?

## Recommended Posts

Flashthinker    100
Hi, I'm new to this forum btw. Anyway, I came here to know if you think it is possible to make a game's 3D engine without using vector math or algebra. And the reason why I'm asking this, is because I found a way to do it, and it seems that no one believes me (in some other forum), and I can't seem to find any documentation on my technique. I'd just like to know your thougths on the matter. [Edited by - Flashthinker on May 7, 2007 9:12:40 PM]

Nypyren    12063

##### Share on other sites
Flashthinker    100
Quote:
 Original post by NypyrenWhat is your technique??

Well, it's pretty feasible to make 3D using trigonometry-only when you've got a single axis of rotation that doesn't change. But when you're making a game you need to change the axis of rotation.

Now the problem I had, was that the programing language I was using (ActionScript - Flash's programming language), does not provide any method for either 3D or rotation around a custom axis... So what I did is used trigonometry to make a set of 3D objects; each having a fixed axis of rotation (in their center), then, I remembered something I was told a while ago; That the same face of the moon is always facing the earth (so we only ever see half the moon), because it roates around itself at the same speed as it rotates around the earth... So I thought that I might use that concept with 3D objects, I made it so that if an object rotates around the "camera" from a distance, it will rotate accordingly around its own axis (except it wil be the inverse effect as the moon)... This worked with anything, even the floor...

Here's how it turned out:
My 3D Engine

- I had to reduce the quality of the texture mapping for speed reasons (Flash is was slow for the proper version)

... But in the end, I decided that ground looked too dodgy (texture mapping-wise), so I just used a mode7 engine instead (only for the ground that is):
My 3D Engine

- Oh, and I haven't done any collision testing yet.
[EDIT]Also, this engine's rotation starts to mess-up after a while; I haven't
uploaded the bug-free version yet... Too slack. (The problem had to do with the Mode7 engine not working in conjunction with the real 3D).[/EDIT]

[Edited by - Flashthinker on May 7, 2007 9:50:14 PM]

##### Share on other sites
jpetrie    13104
I would believe that its possible, within a limited scope, but also that it's a complete waste of time, for a multitude of reasons, except in the realm of academic speculation.

Furthermore, you're going to need to define in more specific terms what you mean by "trig only." For example, the addition operator is not a trig function, but does using it break the "trig only" restriction?

What about matrices? Matrices, in most of their usages in computer graphics, are just conveniently storing regular old algebraic operations (once you resolve the matrix math); does "unrolling" the matrix math count as not using matrices? And if it's considered cheating, what about rotation, which is a bunch of trig encoded into a matrix?

In short, you need to clarify your constraints, otherwise it's impossible to tell if your proposal is a worthless joke or a mostly-pointless academic fantasy.

##### Share on other sites
Flashthinker    100
Quote:
 Original post by jpetrieI would believe that its possible, within a limited scope, but also that it's a complete waste of time, for a multitude of reasons, except in the realm of academic speculation.

Well you're right in that it's a bit slower than vector math, but it also gives me more control for less code, I can deal with angles directly.

[EDIT]No, I haven't used matrices, vectors or algebra for the 3D engine itself. I did use Matrices for the texture mapping *(2D image distortion)* though. What I meant in the question was more of a is it possible without using vectors and matrices than a "is it possible using only trigonometry?"[/EDIT]

[EDIT]I changed the thread's title to avoid confusion.[/EDIT]

[Edited by - Flashthinker on May 7, 2007 9:05:09 PM]

##### Share on other sites
jpetrie    13104
Quote:
 [EDIT]No, I haven't used matrices, vectors or algebra for the 3D engine itself. I did use Matrices for the texture mapping though. What I meant in the question was more of a is it possible without using vectors and matrices than a "is it possible using only trigonometry?"[/EDIT]

Well, that's what I mean -- in that case, then yes, it is completely possible. Consider translation. You can translate (x,y,z) to (x',y',z') with:
| x y z 1 | * | 1 0 0 dx |  = | x' y' z' 1 |              | 0 1 0 dy |              | 0 0 1 dz |              | 0 0 0 1  |

Or by doing:
x' = x + dxy' = y + dyz' = z + dz

The former uses matrices, the latter does not. They do the same thing, however, and that "unrolling" process can be applied to any matrix transform. You avoid vector operations by simply not storing the points as "vectors" (it is debatable of course where the line is between "vector" and "3-tuple" in this context). So it's trivially true -- you can't really say that this "doesn't count" because the trig you use to rotate objects is itself an unrolled version of a rotation matrix (or the matrix is a "rolled up" version of the trig; either way it doesn't matter).

The net effect is that, regardless of how you represent and apply the math, it's still the same math, and as long as its the same math, it doesn't matter (as far as correctness goes) how you represent and apply it.

Quote:
 but it also gives me more control for less code, I can deal with angles directly.

Not true in general (the former, at least). As for the latter, while you might think this is more ideal now, it would quickly become a chore as you got to particularly complex scenarios. Consider the arbitrary axis-angle rotation matrix produce by OpenGL's glRotatef() function. This matrix (and thus the "unrolled" calculations you'd be doing) becomes excruciatingly ugly to write out if you eschew the vector operations used to generate it.

##### Share on other sites
Flashthinker    100
Quote:
 Not true in general (the former, at least). As for the latter, while you might think this is more ideal now, it would quickly become a chore as you got to particularly complex scenarios. Consider the arbitrary axis-angle rotation matrix produce by OpenGL's glRotatef() function. This matrix (and thus the "unrolled" calculations you'd be doing) becomes excruciatingly ugly to write out if you eschew the vector operations used to generate it.

I haven't used either of the two methods you showed. I haven't even touched on anything to do with derivatives or algebra.
Also, to rotate the axis of rotation itself, I could just rotate the 3D points multiple times. The first time, I rotate them around the y axis, and the second time, I could rotate them around the x axis by the number of degrees I want, then I could display the 3D object, then reset the x axis rotation and perform the process over again. It would be the equivalent of rotating the axis itself... It is more processor intensive though.

I guess the reason why I chose to make my engine without using vectors or matrices is because, I have to admit, I'm not that experienced with them... I am a self-taught programmer after all; I needed to play it safe and do with what I know well.

##### Share on other sites
jpetrie    13104
Quote:
 Also, to rotate the axis of rotation itself, I could just rotate the 3D points multiple times. The first time, I rotate them around the y axis, and the second time, I could rotate them around the x axis by the number of degrees I want, then I could display the 3D object, then reset the x axis rotation and perform the process over again. It would be the equivalent of rotating the axis itself... It is more processor intensive though.

But it can gimbal lock much easier. It's also a lot harder to figure out the appropriate sequence of Euler angle rotations (that's what you're basically describing, if I understand you properly) that correspond to one axis-angle rotation in general (especially for weird axes like normalize(0.32,0.111,0.18903).

Quote:
 I guess the reason why I chose to make my engine without any any vectors is because I have to admit, I'm not that experienced witht them... I am a self-taught programmer after all; I needed to play it safe and do with what I know well.

Time to learn. I recommend "The Geometry Toolbox" or "Essential Math for Games and Interactive Simulations." Understanding matrices and vectors is critical to doing anything nontrivial in computer graphics. Even if you can work it so you're using only trig... the API is still doing vector stuff underneath, and you need to understand it.

##### Share on other sites
Vorpy    869
You can program a graphics engine without explicitly using matrices and vectors. They just simplify things. You can also use roman numerals instead of arabic numerals when solving math problems by hand.

##### Share on other sites
No matter what terminology you use, you'll still be performing the same calculations. jpetrie's two translation examples don't just do the same thing, they are the same thing, mathematically speaking.

Matrices just provide compact notation for linear transformations. You are free and welcome to do things in expanded form, and it will all work just fine, but you can say goodbye to hardware acceleration (SIMD operations and all 3D pipelining).

I recommend you bite the bullet and learn vector algebra. If you're competent with mathematics, it will come easy to you. On the other hand, if you aren't so comfortable with algebra, then you'll never make it along the alternative route.

##### Share on other sites
oliii    2196
Doing 3D without matrices and vectors would be like writing a MMORPG in Mindfuck. Just don't do it, learn the tools of the trade, they are not that hard. You don't need a PhD to get started really.

##### Share on other sites
flounder    100
It's neat that you figured that all out on you're own, and it would seem that if you can do all the calculations to display stuff in 3d on your own, understanding how to use matrices and vectors wouldn't be all that hard. However, why are you asking if it's possible to write a 3d engine with you're method when you already have a good start?

##### Share on other sites
Flashthinker    100
Quote:
 Original post by flounderIt's neat that you figured that all out on you're own, and it would seem that if you can do all the calculations to display stuff in 3d on your own, understanding how to use matrices and vectors wouldn't be all that hard. However, why are you asking if it's possible to write a 3d engine with you're method when you already have a good start?

I was just testing to see if it had already been done before.
It probably has, but the frequency is much lower than I thought. Nevertheless, I understand that it is not the way to go. I guess I've never had to resort to matrices and vectors before, but once I get into OpenGL, from what I've heard so far, I will have to. But it probably won't be as difficult as I thought, I'm sure OpenGL deals with a lot of the technicalities; in the end, I'll probably only have to worry about transformation martices...
If I were to program my engine (first post) in Flash using vectors, I'd have to treat each line as a vector, and so, it would have taken me a lot more time to figure stuff like linking the vectors to the points, establishing an efficient 3D matrix-based rotation system, etc...

I'll definitely need to read up on all this math though... I saw some AWESOME screenshots of stuff done with OpenGL (from the Image of the Day forum) and it would be awesome if I could make something like that someday.

##### Share on other sites
oliii    2196
It's not very hard to learn in the context of 3D computer graphics. I can't recommend a good book about it (been a while!), but that would be a step forward.

Head over the article section and look for matrix / vector subjects.

http://www.gamedev.net/reference/articles/article1832.asp

and one of the best resource on the net but can be a bit confusing

http://www.euclideanspace.com/

Probably some other resources on the net, but these are good for starters. The OpenGL Red Book (should be available free online) is nice too, to understand the various types of matrices, and what they can be used for besides the basic transforms. You'll see how vital they are to computer graphics, they are absolutely everywhere. You'll see also all the relation to trigonometry, and your current way of thinking (which isn't wrong per-se). In linear algebra everything's related one way or another.