sin and cos
BlitzPlus Forums/BlitzPlus Programming/sin and cos
| ||
can someone give me a bit of coe that will make a car turn please thanks |
| ||
If RoadLeft= True Dir=(Dir-1) Mod 360 Elseif RoadRight = True Dir=(Dir+1) Mod 360 endif |
| ||
(-1 mod 360) = -1 What you meant is: If RoadLeft= True Dir=(Dir+359) Mod 360 ElseIf RoadRight = True Dir=(Dir+1) Mod 360 EndIf Tho I'm not sure about the status of superjossy's skills, and whether he's one of the many who's driving too fast in his first drivinglessons.. :P |
| ||
What you meant is: No I meant mine, for ease of understanding. I admit that yours would be an acceptable alternative, (Thou not better) solution |
| ||
hm.. I guess the choice is whether one wants the angle to stay within the 0..359 range or within the -359..359 range. My alternative is based on the 0..359 range.. ohwell.. |
| ||
Humm. For me, the choice is if your normal system of use has Dir:+1 implemented as a single command, or if you have memory restrictions and have lookup tables for the subsequent sin/cos equations. |
| ||
I wrote this as an example. I'm not sure if it is what you ment. You can use the cursorkeys to drive the block around. |
| ||
;left/right If KeyDown(203) Then carangle = carangle - 2 If KeyDown(205) Then carangle = carangle + 2 If carangle < 0 Then carangle = 359 If carangle > 359 Then carangle = 0 Are you sure? carangle -2 could be like -2. The correct value should then be 358. +2 and +358, and one single modulo.. :P |
| ||
Thanks b32 !! It is very usefull for me too :))) But I don't understand CS_TBL, what would you change in the b32 code ? |
| ||
Well, the issue is this: He changes angles in steps of 2, rite? So, possible values are 8 6 4 2 0 -2 -4 -6 -8. Next he clips them so that <0 would becomes 359 and >359 would become 0. And there's the problem. A value of -2 becomes 359. The distance from -2 to 0 = '2', the distance from 359 to 0 = '1', so there's where angle errors come from. What I would do: option 1: If carangle < 0 Then carangle = 358 If carangle > 358 Then carangle = 0 But his option is hardcoded for angle-rotations of 2, not exactly elegant. option 2: have a 'speed' variable somewhere, with the value '2'. If KeyDown(203) Then carangle = (carangle + (360-speed)) Mod 360 If KeyDown(205) Then carangle = (carangle + speed) Mod 360 In this solution you can change the speed whenever you want. 'speed' could be any name tho, such as 'angledelta'.. |
| ||
Thanks a lot ;) |
| ||
CB, you are right offcourse. :) Ow .. and, Reno, if you want to rotate masked images, you should use "TFormFilter 0", else the images are smoothened and the transparent background gets blended with the foreground. And I don't know if you're familiar with the LoadAnimImage command ? With LoadAnimImage, you could use one single (big) image that contains all the prerotated frames. It's much easier than loading 180 separate images. |
| ||
Thanks, but I knew that already ;) |