This site is no longer active and is available for archival purposes only. Registration and login is disabled.

Matrix Multipication


Matrix Multipication

Postby RwGast » Oct 11, 2001 @ 7:26pm

I want to multiply two matrix's togather, that are stored in multidimensional arrays. But i want the user to be able to specify the size of the matrix. How could i "ReDim"(for those of you familiar with BASIC) a multidimensional array on runtime?
http://www.angelfire.com/ego/esoteric if you like to play quake3 keep your eye on this site
User avatar
RwGast
pm Member
 
Posts: 1123
Joined: Jun 28, 2001 @ 7:36pm
Location: California, USA


Re: Matrix Multipication

Postby RwGast » Oct 11, 2001 @ 10:59pm

That really sucks when you think someone like digby or dan has probably given you a nice intellgent answer. But instead its just a babling ideot.
http://www.angelfire.com/ego/esoteric if you like to play quake3 keep your eye on this site
User avatar
RwGast
pm Member
 
Posts: 1123
Joined: Jun 28, 2001 @ 7:36pm
Location: California, USA


Re: Matrix Multipication

Postby Dan East » Oct 11, 2001 @ 11:46pm

I don't think I follow your question 100%. It appears you want to know how to dynamically create a 2 dimensional array at runtime. When it comes to true multidimensional arrays in C / C++, you have to specify the array bounds at compile time (one dimensional arrays do not have that limitation - you can dynamically allocate them any size you like). So, since we can dynamically create one dimensional arrays, we can create an array of pointers, then create an array of elements for each pointer:<br>[fixed]<br>//A dynamic "pseudo 2 dimensional" array of ints<br>//Create the main array of int pointers<br>int **MyArray=new int *[xLimit];<br><br>//Now for each int pointer, allocate a new<br>//array of ints which are the actual elements<br>for (int i=0; i<xLimit; i++)<br>  MyArray[ i ]=new int[yLimit];<br><br>//Assign to the 5,3 element:<br>MyArray[5][3]=10;<br><br>//Clean up<br>//First delete all the actual elements<br>for (i=0; i<xLimit; i++)<br>  delete []MyArray[ i ];<br>//Now delete the array of int pointers<br>delete []MyArray;<br>[/fixed]<br><br>Now, that acts like a multidimensional array in the way it is accessed (MyArray[xElement][yElement]), even though it is an array of arrays.<br> The caveats are that more code is required to allocate / deallocate, and although I haven't looked at the actual assembly that example generates compared to a real 2 dimensional array, it probably requires more instructions to access an element than accessing an element from a true multidimensional array.<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: Matrix Multipication

Postby Dan East » Oct 12, 2001 @ 12:06am

Here's another method. This gives you simpler allocation / deallocation, but requires a less intuitive method of accessing an element. Basically you just use a 1 dimensional array large enough to hold the number of elements of the two dimensional array, and do extra calculation to find the desired element:<br>[fixed]<br>//Allocate a one dimensional array large enough<br>//for all the elements of the two dimensional array.<br>int *MyArray=new int[xLimit*yLimit];<br><br>//Assign to the 5,3 element:<br>MyArray[5*xLimit+3]=10;<br><br>//Clean up<br>delete []MyArray;<br>[/fixed]<br><br>Both techniques have their advantages.<br><br>Dan East
User avatar
Dan East
Site Admin
 
Posts: 5264
Joined: Jan 25, 2001 @ 5:19pm
Location: Virginia, USA


Re: Matrix Multipication

Postby RICoder » Oct 12, 2001 @ 12:22am

<iframe src="http://gamercard.xbox.com/RICoder.card" scrolling="no" frameBorder="0" height="140" width="204">RICoder</iframe>
User avatar
RICoder
FOX News Correspondent
 
Posts: 3948
Joined: Jul 10, 2001 @ 1:48pm
Location: the matrix has me


Re: Matrix Multipication

Postby Digby » Oct 12, 2001 @ 3:01am

Use a buffer allocated with malloc and when you need to change its size, use realloc.<br>[fixed]<br>float *pMatrix = (float*)malloc(cnRows * cnCols * sizeof(float));<br>[/fixed]<br>Use the second technique Dan mentioned for accessing the elements of the matrix.<br><br>To resize use realloc:<br>[fixed]<br>pMatrix = (float*)realloc(pMatrix, cnNewRows * cnNewCols * sizeof(float));<br>[/fixed]<br><br>The code isn't high-performance or something that you'd like to put in your game loop but it works. Is this for a class assignment?<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Matrix Multipication

Postby RwGast » Oct 12, 2001 @ 11:22am

Thanks you guys, you pretty much told me all i needed to know. <br>Digby this is not for a class assignment, im just writing my first ppc app in eVC and this is what i decided to do.
http://www.angelfire.com/ego/esoteric if you like to play quake3 keep your eye on this site
User avatar
RwGast
pm Member
 
Posts: 1123
Joined: Jun 28, 2001 @ 7:36pm
Location: California, USA


Re: Matrix Multipication

Postby RICoder » Oct 12, 2001 @ 4:00pm

Digby,<br>  Was it supposed to be a pun that you named the variable "pMatrix" ?<br><br>  I feel like such a geek for pointing that out.
<iframe src="http://gamercard.xbox.com/RICoder.card" scrolling="no" frameBorder="0" height="140" width="204">RICoder</iframe>
User avatar
RICoder
FOX News Correspondent
 
Posts: 3948
Joined: Jul 10, 2001 @ 1:48pm
Location: the matrix has me


Re: Matrix Multipication

Postby RwGast » Oct 12, 2001 @ 5:15pm

Do you use alot of matrix';s when programming games? Like do you do matrix transfermations and stuff?
http://www.angelfire.com/ego/esoteric if you like to play quake3 keep your eye on this site
User avatar
RwGast
pm Member
 
Posts: 1123
Joined: Jun 28, 2001 @ 7:36pm
Location: California, USA


Re: Matrix Multipication

Postby Digby » Oct 12, 2001 @ 5:44pm

RICoder,<br>You really should get away from the computer for a while.  Your geekitude is showing.  That's just Hungarian notation for a pointer variable.<br><br>Robert,<br>Yes, you use matrices quite a bit with 3D game programming.  Matrices make it easy to combine multiple transformations by concatenation.  Some hardware supports matrix operations directly so it's nice if your app uses matrices and can take advantage of it.<br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Matrix Multipication

Postby RwGast » Oct 12, 2001 @ 6:57pm

What do you mean some hardware supports it directly? How would you take advantage of this?
http://www.angelfire.com/ego/esoteric if you like to play quake3 keep your eye on this site
User avatar
RwGast
pm Member
 
Posts: 1123
Joined: Jun 28, 2001 @ 7:36pm
Location: California, USA


Re: Matrix Multipication

Postby Digby » Oct 12, 2001 @ 9:02pm

No current Pocket PC hardware supports it directly so if that's what you're targetting you can relax.<br><br>Modern PC display cards support matrix concatentation and multiplication by a vector.  The Hitachi SH4 supports some 4 component vector multiplications in hardware, as do the current crop of CPUs from Intel (via SSE) and AMD (3DNow!).<br><br>The StrongARM does have an integer multiply and accumulate instruction so that would help with matrix operations using fixed-point data.<br><br>
Digby
pm Insider
 
Posts: 1011
Joined: Apr 29, 2001 @ 1:53pm


Re: Matrix Multipication

Postby RwGast » Oct 12, 2001 @ 9:21pm

No i mean how do you implement this if i wanted to do some matrix functions id just use multi dim arrays and right i function to multiply them, i hardly think that thats how you would do it the cpu suporrted way. Are these directX functions?
http://www.angelfire.com/ego/esoteric if you like to play quake3 keep your eye on this site
User avatar
RwGast
pm Member
 
Posts: 1123
Joined: Jun 28, 2001 @ 7:36pm
Location: California, USA


Re: Matrix Multipication

Postby MirekCz » Oct 13, 2001 @ 3:34am

robert:nor pocketpc nor pc cpu support hardware matrix transformations/whatever. Only modern graphics cards for PC (with t&l) support it. On cpu you either make it the "normal" way - using mul commands (all 80x86,all PPC cpus) or use an additional set of commands to speed things up (modern 80x86 processors - those commands sets are named SSE , 3DNOW and all their extensions...)
With best regards,
Mirek Czerwinski
User avatar
MirekCz
pm Member
 
Posts: 269
Joined: Sep 18, 2001 @ 6:42pm
Location: Poland,city Poznań


Re: Matrix Multipication

Postby RICoder » Oct 14, 2001 @ 4:27pm

Well, then there is the x86 stuff that was introduced with MMX for concatinated integer math...not really matrix, but single vector.
<iframe src="http://gamercard.xbox.com/RICoder.card" scrolling="no" frameBorder="0" height="140" width="204">RICoder</iframe>
User avatar
RICoder
FOX News Correspondent
 
Posts: 3948
Joined: Jul 10, 2001 @ 1:48pm
Location: the matrix has me


Next

Return to Windows Mobile


Sort


Forum Description

A discussion forum for mobile device developers on the Windows Mobile platform. Any platform specific topics are welcome.

Moderators:

Dan East, sponge, Digby, David Horn, Kevin Gelso, RICoder

Forum permissions

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

cron