I'm in the beginnings of developing a "2DAPI" for 3D Gamestudio (which should prove
very useful). I'm trying to get this function to work, but it doesn't. By all means, it
should, unless there's something I should know about a code structure like this:
Code:
struct->struct->member
I think this is where the problem lies, because when I remove the first struct, it works.
You know, I think it would be easier if I just posted the whole code instead of hemming and hawing like this
So here's the
Code:
#include <acknex.h>
#define NONE 1
#define IMG_SIZE 2
#define PAN_SIZE 3
#define MANUAL 4
#define RELDIST 5
#define ABSDIST 6
VECTOR* objCenter= {x= 0; y= 0;}
typedef struct _OBJECT
{
PANEL* panel;
int boundstype;
int boundsX;
int boundsY;
}OBJECT;
void obj_move(OBJECT* obj,VECTOR* move,int flag)
{
float thrustX,thrustY;
while(obj)
{
switch(flag)
{
case RELDIST:
obj->panel->pos_x= objCenter->x - obj->panel->center_x;
obj->panel->pos_y= objCenter->y - obj->panel->center_y;
thrustX= sin(obj->panel->angle);
thrustY= cos(obj->panel->angle);
objCenter->x-= (thrustX * ((key_cuu * move->x) - (key_cud * move->y))) * time_step;
objCenter->y-= (thrustY * ((key_cuu * move->x) - (key_cud * move->y))) * time_step;
obj->panel->angle+= ((key_cul * move->z) - (key_cur * move->z)) * time_step;
default:
break;
}
wait(1);
}
}
And this is the code I use to test the function:
#include <acknex.h>
#include <2DAPI.h>
#include <default.c>
VECTOR* move= {x= 10; y= 10; z= 10;}
PANEL* test=
{
bmap= "aship.pcx";
center_x= 12;
center_y= 16;
flags= VISIBLE | OVERLAY;
}
OBJECT* movetest=
{
panel= test;
boundstype= NONE;
boundsX= 0;
boundsY= 0;
}
void main()
{
video_mode= 8;
video_screen= 1;
screen_color.red= 1;
obj_move(movetest,move,RELDIST);
}
And yes, 2DAPI.h is in the include folder, so the <...> syntax isn't the reason ;)
As you can see, I've created a struct OBJECT* to simplify collision operations (which will be implemented later on, if I can get this to work). The problem is, when I try to use obj->panel->pos_x/y/angle, the function doesn't work. It works when I chage the OBJECT* parameter into a PANEL* and remove the obj-> part, but that's it. The code is to allow for relative movement and rotation, just like c_move in the standard 3DGS functions.
Can ne1 clarify on how (if at all) you use the "struct->struct->member" code? The compiler reads it as valid syntax, it's just not running the function.