Allegro.cc - Online Community

Allegro.cc Forums » Programming Questions » fixed point help

This thread is locked; no one can reply to it. rss feed Print
fixed point help
chaseC
Member #8,368
February 2007

Hi, I am trying to use rotate sprite and when I just do something like rotate_sprite(buffer, image, 0, 0, itofix(angle); it works fine, but if I try to make it rotate int the direction of the mouse like thisint angle = atan2(int(mouse_y), int(mouse_x)); it gives me the error

error: conversion from `int' to non-scalar type `fix' requested

Can someone help? ???

gnolam
Member #2,030
March 2002
avatar

1) atan2() returns radians, so an integer wouldn't have been of much use anyway.
2) rotate_sprite() uses Allegro degrees, which are *128/π to the radian, meaning even if you would have used a float and ftofix it wouldn't have worked the way you wanted it to.
3) The conflict is because you've just met Allegro's Dreaded Fix ClassTM, which overloads the regular trig functions. Include <math.h> before <allegro.h> to scare it off.

[EDIT]
But if you're sure you actually do want to used fixed point (honestly, there's really no need for them on any non-ancient machine), skip the evil overload.
fixed angle = fixatan2(mouse_y, mouse_x);

--
Move to the Democratic People's Republic of Vivendi Universal (formerly known as Sweden) - officially democracy- and privacy-free since 2008-06-18!

chaseC
Member #8,368
February 2007

Oh yeah, I forgot the 128/&pi but it works now Thanks:)

Go to: