do something for 10 seconds
Blitz3D Forums/Blitz3D Programming/do something for 10 seconds
| ||
I am trying to make the wheels rotate for 10 seconds AND SHOW THE ROTATION... I have this code.If KeyHit(208)=True Then ; ######## WHACK THE DOWNARROW jumbo = MilliSecs() For turnage = 1 To 10000 If jumbo = MilliSecs()+1000 Then wheel1=Rnd(0,9) wheel2=Rnd(0,9) wheel3=Rnd(0,9) wheel4=Rnd(0,9) RotateEntity mesh,pit(wheel1),rol(wheel1),ya(wheel1) RotateEntity mesh2,pit(wheel2),rol(wheel2),ya(wheel2) RotateEntity mesh3,pit(wheel3),rol(wheel3),ya(wheel3) RotateEntity mesh4,pit(wheel4),rol(wheel4),ya(wheel4) EndIf jumbo=jumbo+1000 Next EndIfBUT nothing shows... I have an radeon 7000 so I know the card is not too fast... why does this not look like what happens when I do a keydown(57) and jsut random... |
| ||
You're using RotateEntity instead of TurnEntity. |
| ||
yeah... to set the numbers on the wheel on screen. Have to to track them. {{EDIT}} I changed it to turnentity and still just jumped to the final set of numbers. I can't get it. |
| ||
You need to post more code. Also, this condition will always be false in that code:If jumbo = MilliSecs()+1000 Then So nothing between the If/EndIf will ever get executed. [edit] couple of other points from a closer look at that code. First, are you assuming that a For/Next loop with 10,000 iterations will run for exactly ten seconds? It won't. It'll do it in a matter of milliseconds. Second, jumbo=jumbo+1000 should probably go INSIDE the If/EndIf - not outside. I'm really not quite sure what it is you're trying to achieve here... |
| ||
I would code that like this...while not keyhit(1) if keyhit(208) then time=millisecs()+10000 ;time = 10 seconds later than now if time>millisecs() then updatewheels() renderworld flip wend function UpdateWheels() wheel1=Rnd(0,9) wheel2=Rnd(0,9) wheel3=Rnd(0,9) wheel4=Rnd(0,9) RotateEntity mesh,pitch(wheel1),yaw(wheel1),roll(wheel1) RotateEntity mesh2,pitch(wheel2),yaw(wheel2),roll(wheel2) RotateEntity mesh3,pitch(wheel3),yaw(wheel3),roll(wheel3) RotateEntity mesh4,pitch(wheel4),yaw(wheel4),roll(wheel4) end function |
| ||
spin wheels for some time, slowing from an initial speed to zero over time. dim TurnRate#(4) ;set the initial turnrate for the wheels randomly: TurnRate#(1)=10.0+rnd(-3.0,3.0) ;degrees per frame to turn higher number mean faster initial spin. ;do the same for indexes 2-4 dim WheelMesh(4) WheelMesh(1)=mesh WheelMesh(2)=mesh2 ;this is using your already defined mesh/mesh2/mesh3/mesh4 entities but storing their handles in an array instead, easier to manipulate WheelMesh(3)=mesh3 WheelMesh(4)=mesh4 Decay#=0.995 ;adjust to any value between 0.0 and 1.0 to change the rate at which they slow down, and therefore changing the amount of time taken for the wheels to come to rest. repeat HaveWheelsStopped=true for i=1 to 4 turnentity WheelMesh(i),TurnRate#(i),0,0 ;only need to alter the pitch why bother altering the yaw and roll unless you are doing something totally different to what I am thinking you are TurnRate#(i)=TurnRate#(i)*Decay if TurnRate#(i)<0.1 then TurnRate#(i)=0 if TurnRate#(i)<>0 then HaveWheelsStopped=false next renderworld updateworld flip until HaveWheelsStopped=true or keydown(1) |
| ||
Oh Matty that looks fantastic! Shambler... Thanks! BOTH of you have helped... let me tweak that into the code and I will post it if it works (or even if it doesn't!) : ) {{ CODE NOW INCLUDED }} I am trying to do something slightly different. When the wheel spins I need to know (at the very least) what numbers end up showing... Thats why I had the euler angles (of a sort) plotted for every number on the face of the wheel. I could generate a random number and it would be the number displayed on the wheel. If you slapped the spacebar it would (of course) keep generating NEW random numbers and the wheel would give the appearace of spinning. Thats kind of what I was shooting for. BIG PLUS is the gradual slowdown... that helps for a lot of things. But the computer has NO WAY of knowing wht number is showing. Hard to program a check for a win! : ) -RZ If you go to: http://www.silverimports.com/web3ds/ you can see a fil called slots.zip or slotz.zip.. The wheel and texture is in there as well as my source code. Post me a note when you have downloaded it because I will only keep it there for a short time. : ] |
| ||
Shambler... I modified your code to do what I want to do... I just wish I could get it to slow down like Mattys... : ) -RZ |
| ||
You can never = Millisecs()+1000 because Millisecs is always the current counter. Have a quick look at this code: http://www.blitzbasic.com/logs/userlog.php?user=2370&log=435 For the movement, I wanted to do step-by-step walking and turning, but not "jump", but show the turning etc gradually (I did this on the poo pc at work, so might be very quick on most newish PCs.) Although I haven't specifically linked it to time, it could be simply modified to be time-based instead. (replacing the ForNext loops with incrementing Timers and checks against Millisecs() The important note is the calls to the rendering function DURING the movement. |
| ||
Yep Malice I see that now. I should have seen that earlier but I get into the programming fog and can't see clear. It does call DURING movement... one could also increase the interval between turning to make it seem to slow down... :) -RZ |
| ||
Rook - modifying the code I posted earlier it should stop now on the correct numbers although might look a little odd. There are many many ways of doing what you are after, it is possible to pre calculate how fast to spin the wheels initially, how much to decelerate them each frame and how long to do so for based on the numbers they start on and where you want them to end. But if you are after a quick and dirty solution perhaps what is below will help:pit(0)=72 pit(1)=71 pit(2)=38 pit(3)=0 pit(4)=-40 pit(5)=-70 pit(6)=-69 pit(7)=-39 pit(8)=0 pit(9)=39 rol(0)=180 rol(1)=0 rol(2)=0 rol(3)=0 rol(4)=0 rol(5)=0 rol(6)=180 rol(7)=180 rol(8)=180 rol(9)=-180 ya(0)=-180 ya(1)=0 ya(2)=0 ya(3)=0 ya(4)=0 ya(5)=0 ya(6)=-180 ya(7)=-180 ya(8)=-180 ya(9)=180 dim wheelnumbertoendon(4) wheelnumbertoendon(1)=Rnd(0,9) wheelnumbertoendon(2)=Rnd(0,9) wheelnumbertoendon(3)=Rnd(0,9) wheelnumbertoendon(4)=Rnd(0,9) dim TurnRate#(4) ;set the initial turnrate for the wheels randomly: TurnRate#(1)=10.0+rnd(-3.0,3.0) ;degrees per frame to turn higher number mean faster initial spin. ;do the same for indexes 2-4 dim WheelMesh(4) WheelMesh(1)=mesh WheelMesh(2)=mesh2 ;this is using your already defined mesh/mesh2/mesh3/mesh4 entities but storing their handles in an array instead, easier to manipulate WheelMesh(3)=mesh3 WheelMesh(4)=mesh4 Decay#=0.995 ;adjust to any value between 0.0 and 1.0 to change the rate at which they slow down, and therefore changing the amount of time taken for the wheels to come to rest. repeat HaveWheelsStopped=true for i=1 to 4 turnentity WheelMesh(i),TurnRate#(i),0,0 ;only need to alter the pitch why bother altering the yaw and roll unless you are doing something totally different to what I am thinking you are If TurnRate#(i)>=0.1 then TurnRate#(i)=TurnRate#(i)*Decay if TurnRate#(i)<0.1 then ; ; ; ;TurnRate#(i)=0 Tolerance#=2.0 ;degrees to allow either side of. if entitypitch(WheelMesh(i))>pit(wheelnumbertoendon(i))-tolerance and entitypitch(wheelmesh(i))<pit(WheelNumbertoEndOn(i))+tolerance and entityyaw(wheelmesh(i))>ya(wheelnumbertoendon(i))-tolerance and entityyaw(wheelmesh(i))<ya(Wheelnumbertoendon(i))+tolerance and entityroll(wheelmesh(i))>rol(wheelnumbertoendon(i))-tolerance and entityroll(wheelmesh(i))<rol(wheelnumbertoendon(i))+tolerance then ;perhaps check if the entityroll and yaw values are equal to 180 or 0 rather than use a tolerance if they are always 'exactly +-180 or exactly 0... TurnRate#(i)=0 ;you could put a few lines in here that now actually set the yaw, pitch and roll of the wheel to the values in your arrays for pit(),ya() and rol() which will make the wheels jump those final few degrees to their correct position, as if they click into place, although it may look a little artificial. endif ; ; endif if TurnRate#(i)<>0 then HaveWheelsStopped=false next renderworld updateworld flip until HaveWheelsStopped=true or keydown(1) There is an alternative way of doing this |
| ||
Matty: This is what I had done... after the initial spinage you hit the spacebar and it does it again... I like you new idea but you have to wait until the wheel slows down to almost 0 to get the number to pop up. I am going to work onm that. Have to read how you did it. Looks FANTASTIC!!! Thank you. {{ EDIT}} I did it by setting the turnrate like this: For i=1 To 4 TurnEntity WheelMesh(i),TurnRate#(i),0,0 If TurnRate#(i)>=0.1 Then TurnRate#(i)=TurnRate#(i)*Decay yohoo = turnrate(1) If TurnRate#(i)<2 ThenThat way it stops a little faster and results in much less heart attack causing stress waiting for your number to come up. : ) -RZ |