#include<stdio.h>
struct sPoint{
float x;
float y;
};
struct sVector{
float x;
float y;
};
void SetPoint(struct sPoint *,float, float);
void SetVector(struct sVector *, float, float);
void Translate1(struct sPoint *, struct sVector const*);
struct sPoint Translate2(struct sPoint ,struct sVector);
struct sPoint Translate3(struct sPoint , float, float);
void Translate4(float *, float *, float, float);
void main(void)
{
struct sPoint point;
struct sVector vector;
SetPoint(&point,12.0f,45.0f);
SetVector(&vector,1.0f,1.0f);
printf("Point: x=%f, y=%f\n",point.x,point.y);
printf("Vector: x=%f, y=%f\n",vector.x,vector.y);
Translate1(&point, &vector);
printf("Point: x=%f, y=%f\n",point.x,point.y);
point=Translate2(point,vector);
printf("Point: x=%f, y=%f\n",point.x,point.y);
point=Translate3(point,vector.x, vector.y);
printf("Point: x=%f, y=%f\n",point.x,point.y);
Translate4(&point.x, &point.y, vector.x, vector.y);
printf("Point: x=%f, y=%f\n",point.x,point.y);
}
void SetPoint(struct sPoint *p, float x, float y)
{
p->x=x;
p->y=y;
}
void SetVector(struct sVector *v, float x, float y)
{
v->x=x;
v->y=y;
}
void Translate1(struct sPoint *p, struct sVector const *v)
{
p->x+=v->x;
p->y+=v->y;
}
struct sPoint Translate2(struct sPoint p,struct sVector v)
{
p.x+=v.x;
p.y+=v.y;
return p;
}
struct sPoint Translate3(struct sPoint p,float x, float y)
{
p.x+=x;
p.y+=y;
return p;
}
void Translate4(float *px, float *py, float vx, float vy)
{
*px+=vx;
*py+=vy;
}
|