forums.ps2dev.org Forum Index forums.ps2dev.org
Homebrew PS2, PSP & PS3 Development Discussions
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Problem converting c to cpp with matrices

 
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development
View previous topic :: View next topic  
Author Message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Dec 12, 2006 6:22 am    Post subject: Problem converting c to cpp with matrices Reply with quote

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
View user's profile Send private message
rapso



Joined: 28 Mar 2005
Posts: 147

PostPosted: Tue Dec 12, 2006 9:04 am    Post subject: Reply with quote

how du u declare world and tmpworld? probably this are already pointers?
Back to top
View user's profile Send private message
cooleyes



Joined: 18 May 2006
Posts: 125

PostPosted: Tue Dec 12, 2006 5:54 pm    Post subject: Re: Problem converting c to cpp with matrices Reply with quote

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
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Dec 12, 2006 6:59 pm    Post subject: Reply with quote

@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
View user's profile Send private message
chp



Joined: 23 Jun 2004
Posts: 313

PostPosted: Tue Dec 12, 2006 7:09 pm    Post subject: Reply with quote

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
View user's profile Send private message
Ghoti



Joined: 31 Dec 2005
Posts: 288

PostPosted: Tue Dec 12, 2006 7:26 pm    Post subject: Reply with quote

ah okay thanks :)
_________________
My PSP games:

Boxy II: http://www.ghoti.nl/boxyii.php
Elementals: http://www.ghoti.nl/Elementals.php
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    forums.ps2dev.org Forum Index -> PSP Development All times are GMT + 10 Hours
Page 1 of 1

 
Jump to:  
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