Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Trouble with animating a rolling ball...
#1
Today, I started messing around with a program that I shelved a while back. It's a pool game...billiards...or whatever...snooker??

Anyway, I used Lightwave to render 100 sprites as a type of 10x10 matrix. The heading rotates from 0 to 324 from frames 1 to 10...11 to 20...21 to 30...so on...

The pitch rotates from 0 to 324 from frames 1 to 100, at stepped increments of 36 degrees, every 10 frames.

I saved them in ascending order like this...ball000.bmp,ball001.bmp...so on...

Then, I loaded them into an EMS array, in the exact same order.

This code is just a test until I can get the rotation to work right. It does work right if you are only rotating one direction at a time... like If the angle is 0, 90, 180, 270 or 360. When you try to rotate at any other angle, the sprites are all mixed up and it's definetly wrong.

I would post al link to the whole program, but I haven't converted the sprites to 256 colors yet and the filesize would be too much to bother with.

Code:
Blx! = Blx! + Spd! * Tri(Ang).Sine
Bly! = Bly! + Spd! * Tri(Ang).Cine

   IF Blx! < 0 THEN
    Blx! = 0
    Ang = 0 - Ang
   END IF

   IF Blx! > 607 THEN
    Blx! = 607
    Ang = 0 - Ang
   END IF
  
   IF Bly! < 0 THEN
    Bly! = 0
    Ang = 180 - Ang
   END IF

   IF Bly! > 447 THEN
    Bly! = 447
    Ang = 180 - Ang
   END IF

   IF Ang > 360 THEN Ang = Ang - 360
   IF Ang < 0 THEN Ang = Ang + 360


  PicX! = PicX! - (Spd! / 10) * Tri(Ang).Sine
   IF PicX! > 9 THEN PicX! = PicX! - 9
   IF PicX! < 0 THEN PicX! = 9 + PicX!


  PicY! = PicY! - (Spd! / 10) * Tri(Ang).Cine
   IF PicY! > 9 THEN PicY! = PicY! - 9
   IF PicY! < 0 THEN PicY! = 9 + PicY!  

   PicNum = INT(PicX!) + (INT(PicY!) * 10)
  XMSOffset& = PicNum * SpriteSize
  MoveFromXMS BallPage(1), VARSEG(BallSprite(0)), VARPTR(BallSprite(0)), SpriteSize, XMSOffset&
  Future.ROTATEB INT(Blx!), INT(Bly!), 0, 1, BallSprite()

Thanx for any help. Wink
Reply
#2
he,he,he.. I once took a time trying to render a pool ball. I tried realtime texturemapping then...With no result. So good luck with your try!

You calculate each time the new position of the ball, and independently the picture. Why don't you try to relate each position of the table with a picture?

Picy%=(cint (bally!) mod 10)*10
Picx%=(cint (ballx!) mod 10)
Antoni
Reply
#3
Well, I don't think that method would really make it look like it's rolling the way I want. It would definetly be useful for another type of animation though.

I thought about it like this...
Imagine you had a matrix of images 360*360...129,600 images, :lol:

When X increases by one, the image's X-index should increase by one, considering that this is simple... no spinning or anything.

When Y increases by one, the image's Y-index should increase by 360.

It seems simple enough, but NoooOOOooo. I even tried Google, but I haven't found anything yet.

There has to be a trig function for it. Hopefully, I'll find something similar that I can learn from.

Thanks anyway, Antoni!
Reply
#4
RelLensMap :*)
y smiley is 24 bit.
[Image: anya2.jpg]

Genso's Junkyard:
http://rel.betterwebber.com/
Reply
#5
You did something similar to this with RelLensMap? I'll have to look at it. Thanks! Big Grin
Reply
#6
RelLensMap is a great effect, it magnifies a 2d background as if a lens were moving across it. For this is perfect. Yet I don't have it seen emulating a rolling ball with a texture on it. Don't forget a ball can spin.... : :-?
Antoni
Reply
#7
Yeah, what I really need is a trig function. I still haven't been able to find anything on the net. :normal:
Reply
#8
hmmmmm.....

Does the ball ahve a texture/lightsource?

Oz~
Reply
#9
It's all in the first post... I'm not actually rendering in QB. I'm just using a matrix of sprites. I just can't get the images to rotate the direction that the ball is moving. Wink
Reply
#10
Let me insist again with the idea I suggested on friday. Picx% and picY% are a function of the position in the table
Code:
Picy%=(cint (bally!*k1+k2) mod 10)*10
Picx%=(cint (ballx!*k1+k3) mod 10)
K1 must be adjusted to give the rolling effect (probably it must be negative)
K2 and K3 are "slip" constants, avoiding the ball showing the same "face" every time it's in the same place.

I'm at work now and i can't try it...
Antoni
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)