 |
forums.ps2dev.org Homebrew PS2, PSP & PS3 Development Discussions
|
| View previous topic :: View next topic |
| Author |
Message |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Dec 12, 2006 6:22 am Post subject: Problem converting c to cpp with matrices |
|
|
Hi folks,
Hi folks,
i use the matrix functions that were part of the examples in the SDK:
| Code: | void matrix_multiply(float* result, float* a, float* b)
{
unsigned int i,j,k;
float temp[16];
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
float t = 0.0f;
for (k = 0; k < 4; ++k)
t += a[(k << 2)+j] * b[(i << 2)+k];
temp[(i << 2)+j] = t;
}
}
memcpy(result,temp,sizeof(float)*16);
} |
when i use this in a C source file i use it like this:
| Code: | matrix_identity((float*)&world);
matrix_identity((float*)&tmpworld);
matrix_multiply((float*)&world, &world, &tmpworld); |
this works fine.
since its part of a 3d game i want it to be in cpp cause of the object oriented way of programming.
well i copied the code but i got an error with that exact code:
| Code: | bj.cpp:165: error: cannot convert 'ScePspFMatrix4*' to 'float*' for argument '2' to 'void matrix_multiply(float*, float*, float*)'
O | so i tried in doing (float*) infront of the &world, and &tmpworld. This stopped the error but my code is not running anymore.
my question: Why this difference in code? why does my old code won't work anymore? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
rapso
Joined: 28 Mar 2005 Posts: 147
|
Posted: Tue Dec 12, 2006 9:04 am Post subject: |
|
|
| how du u declare world and tmpworld? probably this are already pointers? |
|
| Back to top |
|
 |
cooleyes
Joined: 18 May 2006 Posts: 125
|
Posted: Tue Dec 12, 2006 5:54 pm Post subject: Re: Problem converting c to cpp with matrices |
|
|
| Ghoti wrote: | Hi folks,
Hi folks,
i use the matrix functions that were part of the examples in the SDK:
| Code: | void matrix_multiply(float* result, float* a, float* b)
{
unsigned int i,j,k;
float temp[16];
for (i = 0; i < 4; ++i)
{
for (j = 0; j < 4; ++j)
{
float t = 0.0f;
for (k = 0; k < 4; ++k)
t += a[(k << 2)+j] * b[(i << 2)+k];
temp[(i << 2)+j] = t;
}
}
memcpy(result,temp,sizeof(float)*16);
} |
when i use this in a C source file i use it like this:
| Code: | matrix_identity((float*)&world);
matrix_identity((float*)&tmpworld);
matrix_multiply((float*)&world, &world, &tmpworld); |
this works fine.
since its part of a 3d game i want it to be in cpp cause of the object oriented way of programming.
well i copied the code but i got an error with that exact code:
| Code: | bj.cpp:165: error: cannot convert 'ScePspFMatrix4*' to 'float*' for argument '2' to 'void matrix_multiply(float*, float*, float*)'
O | so i tried in doing (float*) infront of the &world, and &tmpworld. This stopped the error but my code is not running anymore.
my question: Why this difference in code? why does my old code won't work anymore? |
you must use force typecast
just like
| Code: |
matrix_identity((float*)&tmpworld);
matrix_multiply((float*)&world, (float*)&world, (float*)&tmpworld);
|
|
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
Posted: Tue Dec 12, 2006 6:59 pm Post subject: |
|
|
@rapso: I declare it in both situations this way:
| Code: | ScePspFMatrix4 world;
ScePspFMatrix4 tmpworld; |
the only difference is that i this in cpp for in a class header and in the C source i do it just at the top of the source file
@cooleyes: yes i have done that, but why that difference, why do i have to do that in cpp and not in c? _________________ My PSP games:
Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php |
|
| Back to top |
|
 |
chp
Joined: 23 Jun 2004 Posts: 313
|
Posted: Tue Dec 12, 2006 7:09 pm Post subject: |
|
|
Because C++ is not as relaxed when it comes to type checking as ordinary C is, and thats a good thing.
If you intend to always access ScePspFMatrix4-objects using that method, rewrite it to take a pointer of that type, or write a inlined overload that does the conversion for you. _________________ GE Dominator |
|
| Back to top |
|
 |
Ghoti
Joined: 31 Dec 2005 Posts: 288
|
|
| Back to top |
|
 |
|
|
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 vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|