I'm simply trying to use the c library cosine and sine functions, but I am getting a compile error.
I'm using Visual C++ 2008. Here is the code and errors.
Any help will be greatly appreciated.
Speed, x, y and angle are all declared as floats.
1 2 3 4
void move(){
x += speed*cos(angle);
y += speed*sin(angle);
}
1 2 3 4
1>c:\users\gref\documents\visual studio 2008\projects\gl experiments\main.cpp(39) : error C2664: 'cos' : cannot convert parameter 1 from 'float' to 'fix'
1> Constructor forclass'fix' is declared 'explicit'
1>c:\users\gref\documents\visual studio 2008\projects\gl experiments\main.cpp(40) : error C2664: 'sin' : cannot convert parameter 1 from 'float' to 'fix'
1> Constructor forclass'fix' is declared 'explicit'
cos(angle) with cosf(angle)
and
sin(angle) with sinf(angle)
as cosf() and sinf() take float as their parameters (your error message suggest that your cos() and sin() are attempting to typecast "angle" -- parameter 1 -- to something else -- this would be the case if you included the deprecated C header <math.h>)
notice how C++ is a bit smarter - it will return float, double or long depending upon the parameter you send to cos()/sin(). In C (with <math.h>) you had to use cosf()/sinf(), cos()/sin() or cosl()/sinl() respectively.