Jump to content
  • Advertisement
Sign in to follow this  
Esh

having problam using sin and cos functions

This topic is 4269 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi all, there is a part in my code where i'm using sin and cos functions when i'm compiling i get the next compile error: error C2668: 'sin' : ambiguous call to overloaded function error C2668: 'cos' : ambiguous call to overloaded function anyway here is the code:
int iPower = (int)(sin(iY * iX) * 128 + cos(iY * -iX) * 128);
			piSurfaceBuffer[iX + iY * (kLockedRect.Pitch >> 2)] = 
								D3DCOLOR_XRGB(iPower, iPower, iPower);
do you got any idea of what the problam is? thanks.

Share this post


Link to post
Share on other sites
Advertisement
Varaibles iX and iY are of type int, so is iX*iY, but sin and cos is overloaded for float and double. The compiler cannot decide which version of sin/cos should be called, since the int can be implicitly converted to a float and to a double.

Share this post


Link to post
Share on other sites
You should probably also note that sin and cos assume that their argument is in radians, not in degrees.

Share this post


Link to post
Share on other sites
OK. i changed the iX and iY type to float.
but now i get the next compile error:

error C2108: subscript is not of integral type

this is the related code:

D3DLOCKED_RECT kLockedRect;
<...>
piSurfaceBuffer[iX + iY * (kLockedRect.Pitch >> 2)] =
D3DCOLOR_XRGB(iPower, iPower, iPower);


and iPower type is int.





Share this post


Link to post
Share on other sites
piSurfaceBuffer is an array! and you access a float index inside it.
It's the same as if you wrote: piSurfaceBuffer [5.3f] = 10;

It's also funny that the variables iX and iY are floats even though they start with 'i' in the beginning. Don't change the type of your variables just because of a compiler error, that is the worst solution because it ruins the logic of your algorithm (no matter what you are trying to do there). The type of the variables should match the purpose of your program and NOT the requests of the compiler. The solution I recommend is to keep iX and iY as integers and the first compiler error should be solved by simply casting the iX and iY to floats only inside the sin/cos.

Share this post


Link to post
Share on other sites
Thanks :)

By The way:
I got my low rating when I've been banned for some time after posting the same post in about all the existing forums in Gamedev. I had no idea that it was forbidden...

Share this post


Link to post
Share on other sites
also, don't use hungarian notation in variable names. Only stubborn old-schoolers do this. Embedding the type in the variable name means rigid, inflexible code. Instead choose a good name that represents what the data is used for and not what type it happens to currently be.

Share this post


Link to post
Share on other sites
Quote:
Original post by UriKiller
piSurfaceBuffer is an array! and you access a float index inside it.
It's the same as if you wrote: piSurfaceBuffer [5.3f] = 10;

It's also funny that the variables iX and iY are floats even though they start with 'i' in the beginning. Don't change the type of your variables just because of a compiler error, that is the worst solution because it ruins the logic of your algorithm (no matter what you are trying to do there). The type of the variables should match the purpose of your program and NOT the requests of the compiler. The solution I recommend is to keep iX and iY as integers and the first compiler error should be solved by simply casting the iX and iY to floats only inside the sin/cos.


yeah.. that's what i did.
thanks.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!