I saw it now....I used it when I started out my GTA clone....never finished that one. But it was a nice tool to have when I wanted many cars.......:D So it actually was fast enough on my fast machine.....;)
Printable View
I saw it now....I used it when I started out my GTA clone....never finished that one. But it was a nice tool to have when I wanted many cars.......:D So it actually was fast enough on my fast machine.....;)
ok...hehe...
heres a version that creates masks too :)
i think you could use this code to rotate in realtime :) ...if you use something faster than setpixel...
But it will still be faster to mak the pictures at design time....or use the DX version I posted...
Let me say clearly what I want:
I have one picture (32x32) with a white background.
I want to be able to draw the picture at any angle (0-359) with a
transparent background (using color key, white), as FAST as possible.
That's pretty much it,
Arie.
As mentioned... use DXGraphics.
Ok. I mean using DX Graphics, but I'll need some rotating code.
Arie.
No one has a fast rotating code using DDraw?
Arie.
Quote:
Originally posted by Arie
No one has a fast rotating code using DDraw?
Arie.
I am so confused. Was my code not fast enough, or did you just not see it?
The GTA Clone code, works fine within itself.
But when I used the same code in my game, It was too slow.
Any other way to rotate, better than GetLockedPixel?
Arie.
Waiting...
Other suggestions (code) are welcome.
Arie.
Isn't it a little too much code(mod_VSA_surf.bas), and complicated?
Does anyone has another way, simpler one, similar to the GTA Clone?
Thank you,
Arie.
I see that you have a car picture with all angles, you should have just draw according to the angle.
It's not what I'm looking for.
I want a single picture, that 'll be able to rotate in any angle.
Thank you,
Arie.
You can't have everything in the world. Use the code that you got. Choose the fastest one. If it is not fast enough in your code, maybe it is something "wrong" with it, and you can try to build it faster. If that is impossible, try to figgure an other way around, like drawing all the pics in front and use them. You can't notice the diffrence between a car made up of 60 pics or just some rotating code. That is at least my oppinion on that case....
Ok, ok.. relax. :rolleyes:
I just thought that if I'm using Direct Draw, It can easily rotate a surface. but I see that it can't. so I'll go on the traditional way, draw all the angles I need.
Yet, any other suggestions are welcome!
Arie.
Ok, ok.. relax. :rolleyes:
I just thought that if I'm using Direct Draw, It can easily rotate a surface. but I see that it can't. so I'll go on the traditional way, draw all the angles I need.
Yet, any other suggestions are welcome!
Arie.
Now, I want to make my ball game a smooth game with a great collision... Does anyone have a full commented tutorial for this?
Thank you,
Arie.
I updated my engine. AlphaBlit is faster, a bunch of things are fixed (like if vbBlue was maskcolor, it would actually choose red), better things for you to try in Form_Load, updated comments about the sprite loader in the .doc file.
I would really love to know what you did there in that great project.
But, I need a simpler example of collision...
I know I need to check the distance between the two balls,
and if its smaller the 2R then I need to apply a crash between them.
Set an angle and speed, how do I set them?
Thank you,
Arie.
speed should be a no-brainer.
for angle, you'll have to find which image array element of sprite (calling it Ball in this example) corresponds with your angle.
0.0 for angle is straight up. pi / 2 is 90 degrees pointing right
Elem = GetSurfaceElementFromAngle(Ball, angle)
RGBBlit MyBackBuf, Ball.Surface(Elem), x, y
I have 4 balls. When I get to the point of crashing, I got the speed,
but how about the angle? I want it to be done with the crash-in-to ball...
every ball has these two properties: Speed and Angle
I need help!
Thank you,
Arie.
Look at attached and see what you come up with
Nice circles, but, I need a code for the crashing angle set.
VB Code:
Sub PlayerBlockPlayer(iPlayer As tPlayer, iWithPlayer As tPlayer) With iPlayer If Distance(iPlayer, iWithPlayer) <= 32 Then .plVelocity = Int((iWithPlayer.plVelocity + .plVelocity) / 2) iWithPlayer.plVelocity = Int((iWithPlayer.plVelocity + .plVelocity) / 2) iWithPlayer.plAngle = Int( _ (iWithPlayer.plAngle + _ GetAngle(CSng(iWithPlayer.plPosition.posX), _ CSng(iWithPlayer.plPosition.posY), _ CSng(.plPosition.posX), _ CSng(.plPosition.posY)) _ ) / 2) .plAngle = Int( _ (.plAngle + _ GetAngle(CSng(iWithPlayer.plPosition.posX), _ CSng(iWithPlayer.plPosition.posY), _ CSng(.plPosition.posX), _ CSng(.plPosition.posY)) _ ) / 2) End If End With End Sub
GetAngle gets the angle of the line between the two balls.
I need help here.
Arie.
I know this code is wrong somewhere...
Please help.
Two ways of helping:
1) Tell where the wrong step is made.
2) Give a code for ball collision, angle directing.
Thank you anyhow,
Arie.
New_dx_and_dy_ForTwoBallCenters needs these 'current' values
for both circles: posx, posy, dx, dy
if you don't have them, add dx and dy as members of your type.
'declares
Dim slope As Single
Dim perpSL As Single
Dim rise As Single
Dim run As Single
Private Sub New_dx_and_dy_ForTwoBallCenters(BallCenter_A As YourType, BallCenter_B As YourType)
Dim riseA As Single
Dim runA As Single
Dim riseB As Single
Dim runB As Single
Dim x_solvB As Single
Dim y_solvB As Single
Dim x_solvA As Single
Dim y_solvA As Single
Dim mRatioA As Single
Dim mRatioB As Single
Dim mSum As Single
Dim mB As Single
Dim mA As Single
Dim dxA As Single
Dim dyA As Single
Dim dxB As Single
Dim dyB As Single
Dim vxAverage As Single
Dim vyAverage As Single
Dim axPast As Single
Dim ayPast As Single
Dim bxPast As Single
Dim byPast As Single
Dim axFuture As Single
Dim ayFuture As Single
Dim bxFuture As Single
Dim byFuture As Single
axPast = BallCenter_A.posX - BallCenter_A.dx
ayPast = BallCenter_A.posY - BallCenter_A.dy
bxPast = BallCenter_B.posX - BallCenter_B.dx
byPast = BallCenter_B.posY - BallCenter_B.dy
dxA = BallCenter_A.posX - axPast
dyA = BallCenter_A.posY - ayPast
dxB = BallCenter_B.posX - bxPast
dyB = BallCenter_B.posY - byPast
mA = 1
mB = 1
rise = (BallCenter_A.posY - BallCenter_B.posY)
run = (BallCenter_A.posX - BallCenter_B.posX)
Call SlopeAndPerpendicular
mSum = mB + mA
mRatioA = mA / mSum
mRatioB = 1! - mRatioA
vxAverage = BallCenter_A.dx + mRatioB * (BallCenter_B.dx - BallCenter_A.dx)
vyAverage = BallCenter_A.dy + mRatioB * (BallCenter_B.dy - BallCenter_A.dy)
axPast = axPast + vxAverage
ayPast = ayPast + vyAverage
bxPast = bxPast + vxAverage
byPast = byPast + vyAverage
mB = slope - perpSL
y_solvA = (axPast - BallCenter_A.posX + slope * ayPast - perpSL * BallCenter_A.posY) / mB
x_solvA = BallCenter_A.posX + perpSL * (BallCenter_A.posY - y_solvA)
y_solvB = (bxPast - BallCenter_B.posX + slope * byPast - perpSL * BallCenter_B.posY) / mB
x_solvB = BallCenter_B.posX + perpSL * (BallCenter_B.posY - y_solvB)
axPast = 2 * x_solvA - axPast + vxAverage
ayPast = 2 * y_solvA - ayPast + vyAverage
bxPast = 2 * x_solvB - bxPast + vxAverage
byPast = 2 * y_solvB - byPast + vyAverage
BallCenter_A.dy = ayPast - BallCenter_A.posY
BallCenter_A.dx = axPast - BallCenter_A.posX
BallCenter_B.dy = byPast - BallCenter_B.posY
BallCenter_B.dx = bxPast - BallCenter_B.posX
End Sub
Private Sub SlopeAndPerpendicular()
If run <> 0 Then
slope = rise / run
Else
If rise > 0 Then
slope = 999999
perpSL = 1 / slope
ElseIf rise < 0 Then
slope = -999999
perpSL = 1 / slope
Else
slope = 0
End If
End If
If slope <> 0 Then
perpSL = -1 / slope
Else
If run > 0 Then
perpSL = -999999
slope = 1 / perpSL
ElseIf run < 0 Then
perpSL = 999999
slope = 1 / perpSL
Else
perpSL = 0
End If
End If
End Sub
What is all this code for? How do I test it?
I need a simple code:
Angle = ...
After hitting the other ball..
Some calculation..
Arie.
You need to reverse the angle
.Angle = -.Angle
1. Copy the 4 new Dims.
2. Paste into the module or form that has your collision code.
3. Copy the 2 new subs
4. Paste into the modulr or form that has your collision code
5. If need be, change the 4 Dims and Private Sub New_dx_.. to public
6. When you find a collision, call New_dx_and_dy_ForTwoBallCenters.
7. Make sure you are using dx and dy as members of your type
I updated mod_VSA_Surface. AlphaBlit and RGBBlit have a new parameter, and I fixed a bug in FillSurface.
You see, dafhi, no offence but.. I prefer no to use your graphic engine.
I just need to know to what angle to set a ball who hit another ball?
I have the angle of the hitting ball and the angle of the hit ball.
What should I do?
Arie.
Reverse The Angle
Angle = -angle
:D :D :D :D
Tried that...
No way! I'm talking about two balls who hit one each other.
I need to set the correct angle to both balls counting the current angle of each.
How???
Arie.
try this code....its not perfect but it works
VB Code:
For j = 0 To BallStack.Count 'check collition If Distance(.X, .Y, BallStack.Ball(j).X, BallStack.Ball(j).Y) <= BallStack.Radius * 2 And i <> j Then .Speed = (BallStack.Ball(j).Speed + .Speed) / 2 '.Angle = (GetAngle(BallStack.Ball(j).X, BallStack.Ball(j).Y, .X, .Y) + .Angle) / 2 .Angle = GetAngle(BallStack.Ball(j).X, BallStack.Ball(j).Y, .X, .Y) End If Next
This is the part that i'm interested in.
Does anyone has a better code from this one that does the same but in a better way?
Thank you,
Arie.
You should be able to figure it out from this example.
Works great!
but let me know where are you setting the new angle of the balls
after the hit?
Arie.
Hi..
Myself and Cyborg .. some time back had tried hard for making a snooker game..
I found at some place in the net that the perfect collision cannot be simply calculated ..
i.e... simply check whether it has hit a ball or not at every frame..
We must calculate the collision and angle prior to actual collision..
There was some algorithm.. I guess if you search it in the net for Perfectly Elastic Collision, u will find some help..
Regards,
Pradeep
Cyborg.. did u see that bounce.zip.. cool ..
got to read the code now..
Well dafhi cud you explain the algorithm..
Thanks,
Pradeep
Yes i saw it. Its really nice! Im gonna go read that code...Quote:
Originally posted by pradeepkrao
Cyborg.. did u see that bounce.zip.. cool ..
HI,
Theres a problem..
Since it is two balls it works fine..
as you make a ball array.. the performance drops drastically.
More over to check the collision.. you need to check for
n x n - n times... it becomes slow and the velocity increases...
I guess we too had the same problem.....
maby you could simplify the algorithm a bit...i havent looked at it yet so im not sure what can be done.