MaxPhysics Community Project: In Progress (Tweaks)

BlitzMax Forums/BlitzMax Module Tweaks/MaxPhysics Community Project: In Progress (Tweaks)

Tibit(Posted 2005) [#1]
This is the "In progress" topic. Used to post code tweaks and additions aswell as comments and suggestion about that code. If you have ideas or links to sites that may help the project, post them here instead.

All accepted/good tweaks will be added to the library for everyone to use.

Don't hesitate to post your additions or findings here. Share you work and if you are unsure if it works or if it is any good, let all others take a look at it and decide.

All Suggestions go here
Any Examples and Demos here
You can fine the complete source here


Tibit(Posted 2005) [#2]
By Altitudems: (Converted from Pollycode )

Vector.bmx


Tibit(Posted 2005) [#3]
Haramanai post the latest version of your line2d here.


Haramanai(Posted 2005) [#4]
Line2d (As I see it)

About it : I created to use it for a game I wand to create. When I saw Wave's posts about Public Phisics I gived it to the public and converted it to fit the the Vector2d.

Progress : No progress. As the main idea I had for collision with lines breaked. I may see the circle to make it work with the circle. (If anything change I will post it in this post and in this topic)

Testing : I will do the testing again to be sure not to give something wrong (I have doned the testing when this was Line2d) I will change this area for for things to tested be well comers.

Wave. If you wand me to do anything with this just edit the above post and ask me to do so.

EDIT: THIS LINE 2D Was Abandon so I deleted the codebox to make the topic lighter


altitudems(Posted 2005) [#5]
Main.bmx (Converted from Main.cpp)
You will notice I removed a lot of the Glut code
I think we can tackle the timer functions later


Vector.cpp still needs to be done.

I almost have polygon.cpp and .h done.

I'm about half way through converting GameCode.cpp and GameCode.h

Body.cpp and .h are next.

I'm sure I will do some things wrong so there will most likely be a long debuging period when everything is converted. Hopefully someone who knows c++ will help out.

Many of the variable names use abreviations and acronyms that make the code hard to understand, I think once the code is converted we should rename things.


altitudems(Posted 2005) [#6]
I was thinking we could use the blitzwiki for this project, then we could all edit the same code. Collaberation is hard in a forum. Plus it would be much easier to organize the project.

Here is a link:
http://www.blitzwiki.org/index.php/Main_Page

If we do it this way we could still post in the forums and give progress updates so that others start to get involved.

Wave: Since you started this project I'll let you decide to set up a page on the wiki or not.

We could possibly start something here:
http://www.blitzwiki.org/index.php/Category:User_Modules


Tibit(Posted 2005) [#7]
Many of the variable names use abreviations and acronyms that make the code hard to understand, I think once the code is converted we should rename things.
I totally agree.

I'll check into the Wiki right away, Thanks!

I have also considered opening a new category (with topics) in the TNet forums for this project. Then I can make you of you admins for those parts.

Also I can always put up a project page where the project in it's whole is explained (liek the first post). And then link to all other places.

EDIT
Replied in Main topic about Wiki


Diablo(Posted 2005) [#8]
ok then, this is what i got when i translated Vector.cpp


I didn't convert the render functions or the matrix function - i think the matrix function should be done in the Vector header???


Tibit(Posted 2005) [#9]
Great!

Do you know how: FindRoots() and RaySphereIntersection() works and what they do? Can you comment? I'll add them to our Vector2D type. Found here



Can you explain more what the matrix functions do and how they work?


Diablo(Posted 2005) [#10]
sorry, i know c++ (a bit) but not that much about physics, i was converting from here 'Tutorial 7 - Rigid body dynamics\source' i'll have a google ;p

EDIT: ... I seem to recall i have 'Game programming all in one' i'll see if it has anything about physics in thier.

EDIT 2: Have a look at THIS for info on matrices and matrixs

EDIT 3: After some sreacher couldn't find that much about Find Roots apart from ways of doing but i found a little about Ray Sphere Intersection:

One
Two
Three
About Ellipsoids


Diablo(Posted 2005) [#11]
Many of the variable names use abreviations and acronyms that make the code hard to understand, I think once the code is converted we should rename things.


I think a good naming system would be to use a form Hungarian Notation

i use it like this


b = Byte
i = Int
f = Float
k = Object/Type
m_ = Member of (see below for eg)
d = Double
UPPERCASE = Consts
lowercase = type names



Example:

Type testtype
field m_iX:int, m_iY:int
field m_fAlpha:Float
End Type

Local kMyType:testtype = new testtype




BlitzSupport(Posted 2005) [#12]
Nice project. Wave, this is the best introduction to matrices I've ever found. Even I understood most of it when I read it (though I've forgotten it all now)...

http://chortle.ccsu.edu/VectorLessons/vectorIndex.html


Tibit(Posted 2005) [#13]
I personally don't like Hungarian Notation. I like the BASIC style more. i.e. Name if after what it is and see the declearation if you are unsure. I'm even diverting from having our types start with T (Bmax standard). The reason is simple: It's not required because the type is called Vector2D and you can always use the name Vector:Vector2D in any method, function or example.

No offence though, but having everything named: vVector.dX would only lead to me thinking it means DeltaX - the difference in X. Which would not be wrong for a vector. Still I can't see the benifit as we are coding in Max and not C++ ;)

James, thanks for the link. I wish to add that I already know matrix math and vector math, it's just that I was unsure what the purpose of the method was =)

As a matter of fact I'm in the middle of the construction of a beginner tutorial on the subject of vectors and gamephysics.

The root function is for solving the roots of the equation system in RaySphereIntersection(C:TVector2, r#, O:TVector2, D:TVector2, tmin#, tmax#, t# Var)

It would be really useful if we could decrypt what C,O,D are and how to use tmin#, tmax# and t#.

t# is probably where on the line we collide, from 0 to 1.
C could be the circle's position vector


Tibit(Posted 2005) [#14]
Here is some timer code. Additions to this is very welcome. I'm not sure if it should be a part of MaxPhysics, time is important. Anyhow if we are going to use it it needs some improvements.




Robert Cummings(Posted 2005) [#15]
I don't like hungarian notation. I like the standard CPP style like so:

aBigVar:Float
someReallyLongRayCastVariable:Int

Where the first letter is lowercase and the rest capitalized.
There is no need to name a variable with "float" as strict will enforce declaration.

The real reason for having capitals or not is simply a matter of readibility, and having the first letter lowercase is a matter of faster typing, nothing more.

Functions should always have the first letter capitalized though.


Haramanai(Posted 2005) [#16]
Ok I don't know if this is right from Wave's point of view but I added the Line2d to the wiki here : http://www.blitzwiki.org/index.php/MaxPhysics_Line2D
Currently there is a problem with the collideLine method and a demo that uses the reflection method. Pls check for bugs and read the discussion to see whats going on.
If anyone can help with the progress is wellcome. Plus If any one know better way to do thinks that are in the methods or functions pls post them to the discussion.


Tibit(Posted 2005) [#17]
Vector2D.bmx


Line2D.bmx


Line2D_Example.bmx



Tibit(Posted 2005) [#18]
My above post contains my latest additions to Line2D and Vector2D and the Example for Line2D. (Save them and try)

See how Line2D inherits Vector2D and uses many of the methos that already exists in Vector2D.

I don't have more time now and I didn't finnish the collision and reflection conversion (something is wrong). Take a look at it and see what you can do. (Compare with the old version if need be).

The reason I want to return a Vector instead of a line is that in most cases what you want is to alter the velocity vector of an object - not the objects velocity line. But you are most likley to want to collide against the line. So it's a Vector/Line Collision.

As always: Any additions, fixes, comments and suggestions are welcome!

@Haramani you added the Line2D to the right place. When you add a page you also need to link it from the main page. Go to the MAxPhysics Main page in the Wiki and cliock the [Edit] Tab. Add a link to MaxPhysics_Line2D. I have already fixed it for Line2D, but next time you might want to give it a try. When you click edit you will see how a link is supposed to look like, simple change the name to the page you want to add to the wiki. Also the main project plan is also open for EVERYONE to change and add to! Don't be feared by the fact that I started the project, it's public after all.


Tibit(Posted 2005) [#19]
And if someone manage to fix the new Line2D, please update both Line2D and Vector2D with example in the Wiki.

I'll be away for some days now. Til then, good luck everyone and keep going!


Haramanai(Posted 2005) [#20]
Change to the http://www.blitzwiki.org/index.php/MaxPhysics_Line2D
Not yet as Wave's post above but in the getCollidePoint method Of the Line2d.
Pls check the Demo : Line2d_Reflection. For bugs.


Haramanai(Posted 2005) [#21]
As was looking thru the Line2d sugested by Wave 4 posts above I came in a conclusion that if we really have to extend Vector2d the x , y fields by the Vector2d will be the start point of tha line and then the field of Line2d End:vector2d will be the rest.

In my point of view we don't need to extend Vector2d for the Line2d. We can create a method or function so we can take A vector2d from the line2d. We have just to subtract the first Vector2d of the Line from the Last one.
That's all from me. Sadly Wave will be away... so I cannot discuss this with him.(So I will continue as I have posted the Line2d in the blitzWiki)


Tibit(Posted 2005) [#22]
I'm back!

The idea to expand Line2D with Vector2D is so that all methods for changing rotation, checking length, copying, scaling; any vector math that our line would need will automatically be inherited. No duplicate code; Easier omptimizations later.

I agree that to have a Line we only need a Vector and a StartPoint (or EndPoint) or A Startpoint and a endpoint and no Line. I think a startpoint and a vector for the Line itself feels like the most innutive. And the endpoint can still be there, for easy access (Though not 'really' required).

Another possible solution would be for line2D to not extend vector. And with all line math for intersections reflections and such already put inside Vector2D. In which Line2D merly use these method on itself. Though the line/and its start and end points need to be vectors.

Having line inherit vector makes this difference:

*If Inherits Vector
Line:Line2D = New Line2D
Line.X and Line.Y <--- a Vector2D
Line.EndPoint.X Line.EndPoint.Y <--- a Vector2D
Line.StartPoint.X Line.StartPoint.Y <--- a Vector2D

*Line not inherited
Line:Line2D = New Line2D
Line.Main.X and Line.Main.Y <--- a Vector2D
Line.EndPoint.X Line.EndPoint.Y <--- a Vector2D
Line.StartPoint.X Line.StartPoint.Y <--- a Vector2D

*Line as it is now
Line:Line2D = New Line2D
Line.X and Line.Y <--- a Vector2D
Line.EndX Line.EndY
Line.StartX Line.StartY


*Any other idea?


Tibit(Posted 2005) [#23]
I update Vector2D with function for calculating the normal of a vector. In other words how to get a perpendicular vector, right and left side.

It was as easy as this:



Tibit(Posted 2005) [#24]
Woohoo! Circle Collision works! And I manage to do it myself first time ever it works on the first try. We need to mix this with line2D.

Check this out:

Circle2D.bmx - Includes a demo where you push around a circle!
Version: First
Dependencies: import latest Vector2D.bmx



altitudems(Posted 2005) [#25]
Good job. Keep it up guys. I'll be adding some things again soon. I've just been busy with work. We'll eventualy have it.


Haramanai(Posted 2005) [#26]
Ok I Changed the Line2d.

go here : http://www.blitzwiki.org/index.php/MaxPhysics_Line2D for more details in the Comments on Updates, Additions and Fixes section and the source code.


Tibit(Posted 2005) [#27]
I like the new Line2d very much!

A pointer, I would like for the Line2D objects to be called Line:Line2D and not _Line2D:Line2D, as that kinda beats the purpose with having our Line called Line2D and not TLine or something. Same with Vector:Vector2D, I think that makes the code easier to follow. If it's okey for you then we can swiftly fix it with a simple replace. Same with Circle:Circle2D ;)

GetCollideLinePoint() - The place where you divide. I would like to divideup that calculation up on four lines:
Local ua:Float = ( (x4 - x3)*(y1 - y3) - (y4 - y3)*(x1 - x3) ) / ( (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1) )
Local ub:Float = ( (x2 - x1)*(y1 - y3) - (y2 - y1)*(x1 - x3) ) / ( (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1) )
''''''''''''''''''
' Instead of the two line above:
local A = (x4 - x3)*(y1 - y3) - (y4 - y3)*(x1 - x3) )
local B = (y4 - y3)*(x2 - x1) - (x4 - x3)*(y2 - y1) 
local C = (x2 - x1)*(y1 - y3) - (y2 - y1)*(x1 - x3)
If B = 0 return
Local ua:Float = ( A / B )
Local ub:Float = ( C / B )


I fear nill values you see ;)
Local sx# = x2-x1
Local sy# = y2-y1

Local q# = ((px-x1) * (x2-x1) + (py - y1) * (y2-y1)) / (sx*sx + sy*sy)
''''''''''''''''
'' I suggest replacing above lines with these:
Local sx# = x2-x1
Local sy# = y2-y1
local Sq = (sx*sx + sy*sy)
if Sq = 0 return
Local q# = ((px-x1) * (x2-x1) + (py - y1) * (y2-y1)) / Sq



I'll look more into it ;)
I'll let you update the changes, or if you want me to I'll do it.


Tibit(Posted 2005) [#28]
I'm working on your line-circle collide. I wish I manage to make it work with reflection/bounce.

Soon it will be time to put this system together, I'll make a MaxPhysics Main File (which includes every thing) and also the collision planes idea. What it means is that we after that only need to import one file, the Main.


Haramanai(Posted 2005) [#29]
Wave : I have no problem with all your sugestions above.
Make any changes you think it ' s for good.

I can't find so far a good way for the Circle Line Collision responce.

P.S. I have to tell you that I am not a Mathimatician and I don't have the knowledge of Vector Mathimatics and I just searching the Internet and expirimenting to find the solution I wand.


Tibit(Posted 2005) [#30]
Not the best, still need some tweaks. At least it is a working start. Requires some bugfixes in Vector2D so make user you get the latest version of it before you test this demo. Still no changes to Circle2D.


--Bounce/slide--
The solution is at hand:

Strict

Include "Line2d.Bmx"
Include "Circle2d.bmx"
Include "Vector2D.bmx"

Global WallA:Line2D = Line2D.CreateLineXY(10 , 400 , 500 , 500)

Global BallA:Circle2D = Circle2D.Create(200 , 80 , 40)

Global BallB:Circle2D = Circle2D.Create(100 , 50 , 50)
Global BallB_Velocity:Vector2D= CreateVector()

Global Gravity:Vector2D = CreateVector(0, 0.03)'Constant Gravity Acceleration
Global SurfaceNormal:Vector2D = CreateVector(0,0)

Global Reflect:Vector2D = CreateVector(0,0)

Graphics 640 , 480 
While Not KeyDown(KEY_ESCAPE)
	Cls
	
	BallB_Velocity.Add( Gravity )'Apply Gravity
	BallB.Position.Add( BallB_Velocity )
	
	'''''The BallA Loop
	Local pre:Vector2d = BallA.position.copy()
	
	SetColor 0 , 255 , 0
	BallA.Draw()

	SetColor 255,0,0
	BallB.Draw()
	
	If WallA.OverLapCircle2d( BallB )
		SurfaceNormal.MakeRightNormalFrom( WallA )
	
		Reflect = GetReflect( SurfaceNormal, BallB_Velocity )
	
		BallB_Velocity.Add( Reflect )
		BallB_Velocity.Multiply( 0.7 )
	EndIf		

	SetColor 255,155,0'YELLOW
	BallB_Velocity.DrawModify( BallB.Position, 20 ,0 )	
		
	SetColor 255,255,255'REFLECT	
	Reflect.DrawModify( BallB.Position, 20 ,0 )
			
	'''''check for overlap
	Local Dist! = WallA.OverLapCircle2d(BallA)
	If Dist 
		SetColor 200 , 200 , 200
		DrawText "OVerLap , Distance : " + Dist , 10 , 10

	End If

	''To set the BallA Position for testing
	If MouseDown(1)
		BallA.Position.x = MouseX()
		BallA.Position.y = MouseY()
	End If
	

								
	'''The Stage Drawing
	SetColor 255 , 0 , 0
	WallA.LineDraw()
		'to move the wall
	If KeyDown(Key_1)
		WallA.setXY1(MouseX() , MouseY())
	End If
	If KeyDown(Key_2)
		WallA.setXY2(MouseX() , MouseY())
	End If
	
	Flip
Wend


	
	'Get Reflection Vector
	'---------------------
	'This is a part of physics objects when we implement it
	Function GetReflect:Vector2D( SurfaceNormal:Vector2D, Velocity:Vector2D )
		If Not SurfaceNormal Return
		If Not Velocity Return

	
	'	Local A! 	= SurfaceNormal.Dot( Velocity )
	'	Local B! 	= SurfaceNormal.Length() * Velocity.Length()
	'	Local ReflectAngle!  = ACos( A / B )
		
		Local SurfaceAngle!  = SurfaceNormal.Angle()
		Local VelocityAngle! = Velocity.Angle()		
		Local ReflectAngle! = VelocityAngle-SurfaceAngle
				
		Local Reflect:Vector2D = Vector2D.CreateField( Velocity.Length(), ReflectAngle )

		Return Reflect
	
	EndFunction	
	

						
		'Local Reflect:Vector2D = SurfaceNormal.Copy()
		'Reflect.Multiply( 2*SurfaceNormal.Dot( Velocity) )
		'Reflect.Subtract( Velocity )
		
	
	
	
	
	
	
	
	
	
	
	
	


I am not a Mathimatician
Neither am I. Though I have studied physics, mechanics and vector math -linear algebra.


Tibit(Posted 2005) [#31]
Also I saw you added a "help us" headline in Line2D. That is a very good idea and makes it so much easier for people who want to help. That should be a standard in every WIKI page of this project!

EDIT:
Updated Line2D with minor name changes. Made the code a little neater according to me, so no code changes.


Haramanai(Posted 2005) [#32]
Yet another Circle Line Collision Demo but not Perfect.



It look good but it nevers fix the fault that the overlapDist it's smaller than Ball.radius
I believe this is the reason that the ball drill's throu the Line1


Haramanai(Posted 2005) [#33]
The Last demo that I will post for Collision Circle2d before the perfection
I think it's a good place to expirimenting the Functions
Don't forget you need Vector2d.bmx and you can find it here : http://www.blitzwiki.org/index.php/MaxPhysics_Vector2D
and the Circle2d.bmx which is here : http://www.blitzwiki.org/index.php/MaxPhysics_Circle2D


If you push a numeric key the edge with the label of it will go to the mouse coordinates
if you push the left mouse button the ball will go to that mouse coordinates
Last and the funniest : when you build your own map you can just copy paste the outpout from the output tab in the setting Lines section in the code to run the demo with your map. (I was trying to cheat and make a map that will look perfect to make an impression but anyway...)

P.S.1. It's like Iam kicking the Line2d But anyway...
P.S.2. It's buggy don't kill me
P.S.3. don't forget If you know a better way to handle this say it here or say it anonymus in the descution tab of Line2d in the BlitzWiki: http://www.blitzwiki.org/index.php/Talk:MaxPhysics_Line2D


Tibit(Posted 2005) [#34]
It is a good example, when we get this to work we know it will work!

RE: Your example above with the circle. The reason it jumps through the line is because you alter the speed only, not the possition. So every time it passes the line, you tell the ball to Change (reverse) direction. It does and starts to go up, then gravity pulls it down again. Until the velocity is so low that it doesn't matter if you reverse it anymore.

Also a note about force and velocity. They are not the same ;)


Haramanai(Posted 2005) [#35]
For the problem of the circle collision I believe the solution of the problem lies somewhere in this document :
http://www.fluidstudios.com/pub/FluidStudios/CollisionDetection/Fluid_Studios_Generic_Collision_Detection_for_Games_Using_Ellipsoids.pdf
I am still tying to find my way in this.
I recommend you to have a look in this document it looks like that is a standard one.

Also I found out that the Line2d that I had bothered you all this time it's not necessary for the Mod. The reason I am writing this up is that I created some functions to get rid of them.(It's like I am destroying me own creation but how cares)
here are some examples:
edit: Well I don't have the function in this CPU so maybe this function not correct but I have it in an other CPU at home I will change it if it is not the one.
	Function LikeLine:Vector2d(Vector:Vector2d , VectorOrigin:Vector2d)
		Return Vector2d.create(Vector.x - VectorOrigin.x, Vector.y - VectorOrigin.y)
	End Function



The names of the functions of course are not standard they may have any name.
But the result is that there working like the lines where working.
I have somewhere and the clasic demo that I have made with the lines but only for collision.
Here it is:

It's not organised like the others but it's a good example to catch what I am thinking right now.
I am not going to dive in the Matrixes (Because I am afraid Smith) because it's to much for me and I can't and don't want to understand them. So simple trigonometry for me and linear algebra(without Matrixes).
Thats all I just working almost all my free time on this so I had to tell what I am thinking to someone


Tibit(Posted 2005) [#36]
Okey, perhaps we should skip Line2D. The important thing is that the system is flexible and module.

I had this idea with circle/line collision, perhaps it is better to check the circle Velocity Vector against the line instead? In that way an object can never pass through another object. The velocity vector is increased with the radius of the object before collision test.

And to draw a vector please use:

VectorYouWantToDraw.Draw( StartVector )

To create a vector outside of the library itself use the functions:

NewVector:Vector2D = CreateVector( 55, 100)
Or
SomePoint:Vector2D = Point( 33, 10 )

EDIT

Good link, checking it now.

EDIT

Really good! Polygons here we come!


Haramanai(Posted 2005) [#37]
The first part of the document have done with great success. I also done it in a way to be like a tutorial
check it out


P.S. As you can see I still use the Line2d. As you said it give great flexibility so I think it will stay for sometime more to make our life easier until the completion.
Also it may be good idia if will add a better vertion of this in the main tutorial section of the comunity to attract more people to help.


Tibit(Posted 2005) [#38]
Great! Yet it doesn't seem to detect the edges correctly?

I'm almost complete with a vector physics tutorial for beginners! Let's post these at the same time.


Haramanai(Posted 2005) [#39]
The detection of the edges it's not a problem of the implementation. The document deals with edges later on. As far I understand we will have to find out ourselves a way to deal with edges of a single line, because the document doesn’t cover this think.
After all if I post this tutorial it will be a work in progress tutorial that it will be completed part by part in the post. Like the nehe tutorial.
Just tell me when you wand to post them.


Tibit(Posted 2005) [#40]
After all if I post this tutorial it will be a work in progress

True, Go ahead and post it, I'll post mine in another topic when it's done and link here. I'll update my guide with some stuff from the library as we progress.


Haramanai(Posted 2005) [#41]
I have to organized a litle bit more but I don't have the time for today so I will post it sometime tomorow


Robert Cummings(Posted 2005) [#42]
why not have a convex hull class instead of seperate box and circle? a convex hull with enough edges easily represents a circle.

Might make the core code a lot simpler with very little speed difference (most physics engines are based around response, not number of objects)


Tibit(Posted 2005) [#43]
Explain more.

Convex Hull?

Code Simpler?

Based around response not number of objects?

Any code example?


Haramanai(Posted 2005) [#44]
He must mean a 6 or more sides pollygon to be like Circle.

Wave I am allready stuct in the document for elipsoid can I use the Circle2d in the wiki? So to post early examples and faild codes in the discution area to get help. and not overload this post?
It will be ok with you if I do not post the tutorial that we were talking yesterday?(sorry about that.)


Tibit(Posted 2005) [#45]
no problem. Please use the Circl2D. And if you change a lot you can always post it here. Id on't think we can overload these forums with this project, it's not that big. Anyhow, if you post in the Wiki add a post here to draw my attention :)

Note that there is a problem with ovals, and that is when they rotate. But it that is solved (did the guide adress that?), wow!

Right now I'm fixing the vector2D to respond to collidion against any surface. In this way our Shapes does not need to have collision mehtods themselves, they simple calculate their surfacenormal and pass it to the collision function.

Also I don't like the idea of adding Gravity (like the guide) inside the collision method, that sounds crazy to me. What about if we have more forces than gravity, such as gravitywells, explosions, fans.. Force should be applied, then it accelerated, acceleration makes us move - increase speed. The velocity is what we check and change in collision.

Still if you manage to convert the collisions from the guide, most problems are solved.


Tibit(Posted 2005) [#46]
Projection work nice!
But reflection N Mirroring is Wierd!
'Projection and Reflection
Import "Vector2D.bmx"

Graphics 500,500,0

Global Line:Vector2D 		= CreateVector( 300, 00 )
Global LineStart:Vector2D 	= CreateVector( 10, 200  )

Global Vec:Vector2D		 	= CreateVector( 0, 0 )
Global VecStart:Vector2D 	= CreateVector( 200, 20 )

Global Project:Vector2D	 	= CreateVector( 0, 0 )


While Not KeyDown( Key_Escape )
	
	SetColor 255,0,0'RED 
	DrawLine LineStart.X, LineStart.Y, LineStart.X + Line.X, LineStart.Y + Line.Y
	
	SetColor 0,255,0'BLUE
	Vec.Set( MouseX() - VecStart.X , MouseY() - VecStart.y  )
	Vec.Draw( VecStart )
	
	If KeyDown(Key_1)
		LineStart.Set( MouseX() ,MouseY() )
	End If
	
	If KeyDown(Key_2)
		Line.Set( MouseX() - LineStart.X, MouseY() - LineStart.Y   )
	End If
	
	SetColor 0,0,255'GREEN
	Project.ProjectionOf( Vec, Line )
	Project.Draw( VecStart )
	
	Local SurfaceNormal:Vector2D = Line.CreateLeftNormal()
	SurfaceNormal.Normalize()
	
	SetColor 0,255,255'TEAL
	Project.Mirror( SurfaceNormal ) 
	Project.Draw( VecStart )		
		
	SetColor 255,255,0'YELLOW
	Project.ProjectionOf( Vec, SurfaceNormal )
	Project.Draw( VecStart )				
	
	
Flip;Cls	
Wend



Haramanai(Posted 2005) [#47]
Cool demo those function are nesesery. The reflection that I made for lines it's realy crazy I can't even remember how I have done them. But as they are working we can keep them and just mark them to remember that we must make them clearer in the future.
About the elipsoid I don't think that it will be a problem with rotation. Plus gravity it's not added in the collision method. As you can see all the forces will be added to the position and then we have to check the data from the old position to the new and find were the collision will take place and make the responce.
About velocity. If you break it you will see that it's just force the force that it's nessesary to travel from one position to another in the given time.

Something about the Projection. To make the seperation axis method we need to drop the projection from 2 dimentions to 1 dimention. I was trying to make this to work for sometime now but sadly with no luck.

Last somethink about me. Here in Greece it's raining for 3 days now and I am working under the rain. My health it's too bad right now. I may be off for sometime, work it's hard and does not give me free time that I wand.


Tibit(Posted 2005) [#48]
You are doing a great work! Take a break if you need to, don't feel to obligatied to the project.

Go here to checkout your line demo working with BOTH bounce and or slide! Soo cool!
IT WORKS! So far so good!

The golden function!



Tibit(Posted 2005) [#49]
PhysicsObjects and CollisionPlanes. All in the mix now. Take a close look at this, and at Circle2D. Make Line2D extend Shape2D just like Circle2D does.

Still this example is not working correctly.. Time.. I'm NOT going to use MaxPhysics in my game, not at this time. I'm doing a simpler implementation into what I already have. So for my part I'm putting this project on-hold. Still I wanted to share what I have so far:



If someone wants to continue the work on the core or add new features, please do so. And if you have questions: Don't hesitate to ask!

Later,
Wave~


Haramanai(Posted 2005) [#50]
This means that you are out from the project?


Haramanai(Posted 2005) [#51]
Well anyway...
Just a transletion of the PolyColly code...
It's hust from the first tutorial
The Polygon.cpp

WE DON'T HAVE TO TRANSLATE ALL THE FILES OF THE POLYCOLLY.

Just the Polygon.cpp from all the tutorials and fit them to the Clasic 2d Coordinate system and Vector2d.

Edit : I deleted the codebox to post it to another post


Tibit(Posted 2005) [#52]
I'm not out, I'm just less active.

RE: the coordinate system, is there a reason for it? I had that in my library before, and I din't notice any big difference in function.

Do you know how to make a reflecting vector from a poly? That would be awesome. Then we can put them all together. Also I found and fixed a bug in the circle/line collision response, seems to work much better now. Still the circle vs circle collision is a bit wierd.

See in programming forum, my post for Physics Help.


Haramanai(Posted 2005) [#53]
All comes from this: http://mathworld.wolfram.com/Reflection.html
(My English are not good so I have a problem to explain this stuff).
It's not difficult to create a reflection vector from poly. You just have to now the collision point. From the collision point you get the side of the poly. Then with the method MakeLeftNormal you get the Normal of the side. Just remember that when you create polygons you have to create them clockwise
After that you have to find the minimum angle between your Vector and the normal of the side. This angle it's the master of the new reflected vector.
And here comes the crazy code:
Side.MakeLeftNormal() 'Create the Normal from The side
Local an# =  Side.getAngle() - Vector.getAngle() 'The angle between the Normal and the Vector
Local ReflectedVector:Vector2d = point(1 , 1) ' Just a Vector with length and direction to be sure that the methods will work
an = Vector.getAngle() + an*2  ''' Two times the Angle between the normal and the Vector
ReflectedVector.setDir(an)
ReflectedVector.setLength(Vector.getLength())
ReflectedVector.reverse() '''' The last step 

The edges of a polygon it's a different story and I don't know how to handle them.


Haramanai(Posted 2005) [#54]
I just realized that the polygons to work corect must have the first point seted to zero and to be created clockwise.


I also made a simple Polygon creator to make the testing easier.
Here it is :


Pls test and play around and tell me if you found any problem.

EDIT:I Deleted the codebox of Poly couse I had posted A new vertion of it 3 post down


Tibit(Posted 2005) [#55]
I've been working with the collision response, Dynamic vs Static and Dynamic vs Dynamic objects seems to work now. The Shape we suse should now not matter. In other words the slide/bounce should work the same for circles and lines and polygons, but I need to put it all together.

Nice going with the polygons, I would need the collision method to return a vector. This vector should be the length N direction required to push the polygon out-of-collision.


Haramanai(Posted 2005) [#56]
Wow... PolyColly turns to be the worsest Document I ever readed.

There 3 options as I see it right now.

1. Just Translate and getted work the Polygon.cpp from the source code(we have to find out wich one is the best for us)

2.Just delete the code on the paper and try to impliment the saying. (code it from the begining)

3.Find a better document that dealing with polygons(If you know any tell me)

To tell you the truth I vote 3. But I can't find anything so far.


Haramanai(Posted 2005) [#57]
Well as I cannot find any other tutorials I am going to use PolyColly :(
I will go between the Polygon.cpp and the document to find out the right way for it.


The offset that Passes to the Collide method turns to be the MTD(minimum translation distance)
Be carefull couse this is still the tutorial 2 to deal with speed I have to done the tutorial 3.


Tibit(Posted 2005) [#58]
I guess this already encompass what you have done with polygons, but take a look at it. It might help.

(It is not made by me, but I think it is free to use)


I would never think collision detection and collision response was this complex as it proved to be.

But if we take one step at a time, eventually we much reach our goal. *wait* Where did this wall come from?


Haramanai(Posted 2005) [#59]
I konw it sometime before I have seen it. It's nPoly.
It's Not so good as this I am trying to do now. For example they are not overlap.
I will try to finish it right now I m trying to make tutorial 3 and it's checking Velocity to find out where the objects collide. Just see the example 3 from the bin of the PolyColly zip.
The problem is that just a translation of the polygon.cpp or from the pseutocode from the document are not working.
It took me some time to figure out a way for the 1st and 2nd tutorials.
So it will take some time to find out how to do tutorial 3.
It's a really headache but I will try my best( just bought a book for C I hope it's not to diferent from C++)

As the tutorial 3 the polycolly it's finished...(in a way) and in the future we will add the ability to rotate.


Tibit(Posted 2005) [#60]
I guess Altitudems is doing the conversion too. I just hope he posts any new sections he converts, so you don't both work on the same thing.

C and C++ is not the same thing, from what I have been told. However I still have very little (next to none) experience with either.

Rotate = Nice! Does pollycode use "projections" or some other teqnique? You don't have to worrie about the physics, I think they work. I'll see if I can put it all together soon.

Anyhow, the pollycode examples are awesome, however they are not simple to use, MaxPhysics will be very easy to use, even for beginners, that is my goal.

Also I do feel, like you said before, that we are the only onces working on this project. However, if you need help with anything, including C++ conversions, ask in Blitzmax's programming forum. It is very likley you will get more response if you ask direct questions there. Don't assume that anyone, or those who can help, will look here. Contrary to this being a Community project it more feels like a Commercial project.

So what do you say? 25$ for the Physics Module?


altitudems(Posted 2005) [#61]
I am still working on the conversions, but I am taking a new aproach. Instead of doing a straight conversion. I'm trying to redesign the structure of the code as I convert. That way everything is more object oriented and easier to use in a real world game. Unfortunetly the code I have is far too broken to post, but possibely this weekend I'll post some code.

Sorry I havent been very involved publicly. I'm a pretty busy person. I'm a working musician, magazine art director, and operate a design firm, among other things. Its hard to fit in time for Blitz.


Haramanai(Posted 2005) [#62]
Wave: No way to put money on it… Money will destroy relationship and will ruin our lives.
We wand to create games and with utilities we will have to have customer support for life time if we wand to be respectful persons.
Plus we will gain from the community when this project it’s over and BRL put it to their Modserver (I hope they will )

Altitudems: Pls don’t disappear again polygons are a must. Pls post your progress.
I have a ULM book but for the time sits to shelve. It will be great if you can mail me your sketches of the reconstruction of the code.

I don’t have a safe mail right now but I will put both of you in my conducts.

P.S. Whoouaoou… this project have a great learning curve I am glad that I am in it and haven’t been kicked ( till now )


Tibit(Posted 2005) [#63]
Selling it for 25$ was more a joke to see which reads this thread. I to feel that I have gained a lot of experience on the project. Unfortunatly I'm quite sick and tired of programming by now. *sigh*

Anyhow I do really hope and wish this project will succeed and become something..


Tibit(Posted 2005) [#64]
I have worked out the problem with elasticity. Also I have found a good optimization in circle vs circle (takin out the sqr() ).

What's next?

Yes, I'm going to put all it together and wish for it to work.


Haramanai(Posted 2005) [#65]
Is it working?


Fetze(Posted 2005) [#66]
I don't know, how optimized your code is, but I've worked out a couple of optimized Math-Functions some months ago. Maybe they could help?

Function Distance:Float(fParX1:Float, fParY1:Float, fParX2:Float = 0, fParY2:Float = 0)
	Return Sqr((fParX1 - fParX2) * (fParX1 - fParX2) + (fParY1 - fParY2) * (fParY1 - fParY2))
End Function

Function DistanceQuad:Float(fParX1:Float, fParY1:Float, fParX2:Float = 0, fParY2:Float = 0)
	Return ((fParX1 - fParX2) * (fParX1 - fParX2) + (fParY1 - fParY2) * (fParY1 - fParY2))
End Function

Function IntDistance:Int(iParX1:Int, iParY1:Int, iParX2:Int = 0, iParY2:Int = 0)
	Return Sqr((iParX1 - iParX2) * (iParX1 - iParX2) + (iParY1 - iParY2) * (iParY1 - iParY2))
End Function

Function IntDistanceQuad:Int(iParX1:Int, iParY1:Int, iParX2:Int = 0, iParY2:Int = 0)
	Return ((iParX1 - iParX2) * (iParX1 - iParX2) + (iParY1 - iParY2) * (iParY1 - iParY2))
End Function

'iParXD = (iParX1 - iParX2)
'iParYD = (iParY1 - iParY2)
Function ApproxDistance:Int(iParXD:Int, iParYD:Int)
	Local iMin:Int
	Local iMax:Int
	
	If iParXD < 0 Then iParXD = -iParXD
	If iParYD < 0 Then iParYD = -iParYD
	If iParXD < iParYD Then
		iMin = iParXD
		iMax = iParYD
	Else
		iMin = iParYD
		iMax = iParXD
	EndIf
	
	Return (((iMax Shl 8) + (iMax Shl 3) - (iMax Shl 4) - (iMax Shl 1) + (iMin Shl 7) - (iMin Shl 5) + (iMin Shl 3) - (iMin Shl 1)) Shr 8)
End Function

Function Angle:Float(fX1:Float, fY1:Float, fX2:Float, fY2:Float)
	Return (ATan2(fY2 - fY1, fX2 - fX1) + 450.0) Mod 360.0
End Function

Function IntAngle:Float(iX1:Int, iY1:Int, iX2:Int, iY2:Int)
	Return (Int(ATan2(iY2 - iY1, iX2 - iX1)) + 450) Mod 360
End Function

Function TransformCoord:Byte(fVarX:Float Var, fVarY:Float Var, fAngle:Float, fParCenterX:Float = 0.0, fParCenterY:Float = 0.0, fScale:Float = 1.0)
	Local fTempAngle:Float = Angle(fParCenterX, fParCenterY, fVarX, fVarY) + fAngle
	Local fTempDist:Float = Distance(fVarX, fVarY, fParCenterX, fParCenterY) * fScale
	fVarX = fParCenterX + Sin(fTempAngle) * fTempDist
	fVarY = fParCenterY - Cos(fTempAngle) * fTempDist
	Return True
End Function

Function IntTransformCoord:Byte(iVarX:Int Var, iVarY:Int Var, iAngle:Int, iParCenterX:Int = 0.0, iParCenterY:Int = 0.0, fScale:Float = 1.0)
	Local iTempAngle:Int = IntAngle(iParCenterX, iParCenterY, iVarX, iVarY) + iAngle
	Local iTempDist:Int = IntDistance(iVarX, iVarY, iParCenterX, iParCenterY) * fScale
	iVarX = iParCenterX + Sin(iTempAngle) * iTempDist
	iVarY = iParCenterY - Cos(iTempAngle) * iTempDist
	Return True
End Function


Notice, that my Angles start with "straight up" for 0° and increase turning right.


Tibit(Posted 2005) [#67]
I think we have those Math-Functions, as vector functions. However ours may not be 100% optimized in all cases.

Checkout the Vector2D.Bmx file. Take a quick look at these and see if ours are the same or not. Every (Almost) math thingy is in there.


Russell(Posted 2006) [#68]
It's been 8 months: Did this ever get completed?

Russell


Armitage 1982(Posted 2006) [#69]
i think not :(
so bad


Russell(Posted 2006) [#70]
I guess we are waiting on someone to 'convert' ODE to BlitzMax module format? It exists for B3D, so maybe not too difficult?

Russell


VIP3R(Posted 2006) [#71]
Just so that you know, a JV-ODE module already exists for BlitzMax on Win32 platforms - see the JV-ODE thread in the Blitz3D Userlibs forum area.

[edit] Actually, it's about time there was a JV-ODE BlitzMax Module thread in here.


Russell(Posted 2006) [#72]
I was really hoping for a cross-platform ODE... The Win32 one seems to work great! It'd be nice to have this on all platforms, though. :)

Russell


VIP3R(Posted 2006) [#73]
Thanks Russell :)

Yep, it would be great to have JV-ODE working on all platforms, but unfortunately I don't currently have access to any of the Mac platforms ( PPC / Intel ).


Russell(Posted 2006) [#74]
I wish I had an extra Mac Mini lying around for ya ;)

http://www.futurepowerpc.com/scripts/product.asp?PRDCODE=APDT-MA607LLA&REFID=PW

($599US aint too bad a deal, really).

Russell