2D Physics: Ideas for a Community Project

BlitzMax Forums/BlitzMax Programming/2D Physics: Ideas for a Community Project

Tibit(Posted 2005) [#1]
The MaxPhysics Project

The vision is to create a solid expandable and flexible 2D physics module for Blitzmax, which will easily be expandable into a 3D version in the future. It is going to be public and open source. Anyone can add their improvements and suggest ideas and tips.

Here is a first topic to focus on the project plan and overall ideas about the project. Here I want everyone who is interested to discuss what they would want from the Physics Module. - Or perhaps we should split it up into more than one module?

--- Points to Decide upon ---

[ ] Find a Name for the Project. Key words: Physics, Vectors. Right now it's "MaxPhysics"

[ ] How is code management going to work? How can we avoid the problem that more than two may be working on the same part? I suggest one file for each type (not always though).

[ ] What about coding styles? Guidelines to make the code similar (as much as possible) for everyone in the project, includes how and where to add comments and formation of the code. - Right now you should try to follow my style in the vector library (see some post below), comments are welcome.

[ ] Referense List
Some about Collisions /f Visual Basic
Flipcode - Collison detection in 3D
N collision, Vector collision /w source in Flash
Hugo - Physics, Effects and Collisons
[a ] no link [/a]

TO DO:
[100%] Finnish the project plan and start the actual project in another topic

Here is my first overview of the project plan, I will update this according to suggestions.

Project Plan - MaxPhysics
[ ] Based upon a solid vector library
[ ] Types: Vectors,Lines,Polygons?,Rects,Cricles
[ ] Collision Checks (above types)
[ ] Collision Response (above types)
Requires we know the point of impact and the speed of impact. With that we could choose anything from perfect slide to perfect bounce, depending on settings.
[ ] Collision Response :Physics Object
When two "lose" objects collide, take momentum into account. These physics objects have a Mass,Position,Velocity,Acceleration. Any object in your game that you want to use with collisions can be derivied from this "physicsObject" and using one (or more?) of the collision types. For example:
Ship extends MaxPhysicsObject
New()
CollisionShape = new Circle( ShipSize )

Perhaps we can also include torque here so that rotation is affected by collisions to.

[ ] Examples and Documentation!
This is very important so that everyone can use this module with ease!

End Notes:
The Physics Library is supposed to be very simple to implement and use, while being as general purpose as possible.




--------- WORK DONE SO FAR ---------
The Second version of the new improved vector library is done. I haven't added anything with physics or collision or lines yet. Here is the start:

Thanks to Haramanai for conversion to real cartesian coordinates.

Anyone may add and improve to this. Make sure that you, in the comments at the top of the file, write what have changed and what adition you have done or bugs you have discovered, perhaps even fixed.



Tibit(Posted 2005) [#2]
A simple demo with only very simple vector math. Don't look to much at the code, I was lazy when I did this, see this only as a first demo.

Tech Demo



Shagwana(Posted 2005) [#3]
May i draw your attention to this thread started a while ago, theres some intresting stuff located within!. Might be of use to this.


Haramanai(Posted 2005) [#4]
Good demo.:) Looks like you are a good organizer of thinks! I also liked your tutorials. currently I am creating something like that based on line segments. I will help if I can. Just tell me how I can be involved.


Luke.H(Posted 2005) [#5]
Looks good,

I was trying to make something like that but based on polygons for a game but I can’t work out collision responses with rotation (and heaps of other stuff)

It is poorly made (it is was only meant for me), but it might help?



I would like to help too, if I can


IPete2(Posted 2005) [#6]
Yes as I stated in that post (link above) this is a great idea, I just wish I had some time to try.

IMHO I think we need a simple to access, powerful toolset, which can be used by simply passing the name of an entity to a function. What happens underneath should happen totally automatically.

I have been working hard with Flash and Director this year, and one of the books I have managed to get hold of is excellent for this kinda thing.

I've yet to understand most of it, but when I do...

;)

IPete2.


Tibit(Posted 2005) [#7]
Luke, that is a very good start! Perfect base to build upon.

Pete, I agree with you. Tell me more how you would like it to work, simple example (skip the underlying magic for now).

I'll try to put these things together into the very base.


Tibit(Posted 2005) [#8]
Move to Top of Topic


Haramanai(Posted 2005) [#9]
The coordinate system you are using it's not good(no ofense of course). the reason I say that it's because it's not based on the Cartesian coordinate system. To do that you have to have the 0 angles at the right and 90 angles at the up. To do that you have to get angles this way atan2(-y , x). And then
x = cos(angle) * Length (the same with yours. but..)
y = - sin(angle) * Length

I am not saing that you are wrong but it's better to work with Cartesian coordinate system as it ise more clasic and we will find solution for problems more easily.
The system that way works good with the negativy values that you are getting when you overcome the 180 angles or when you are giving over 180 angle e.g. 270. that equals to -90

If you wand to get always positive value you just have to put inside the method
if angle< 0 then angle:+360

Here my HAVector2d that I have done this morning


EDIT: And here are the changes in TVector (I don't know if I forgeted somethink)

EDIT2: And from wikipedia fro Cartesian Coordinate System : http://en.wikipedia.org/wiki/Cartesian_coordinate_system


Tibit(Posted 2005) [#10]
Good work, I agree with you on this. I never thought about it. It's just that (I think) the graphics are drawn with inversed Y-axis. Anyhow using the normal system feels more at home for me too.

Any suggestions for the formation of TVector? I mean will you use the new TVector?

I like where this is going, also checkout this: soldiers.250free.com/BlitZMax/Polycolly.zip
Download and run the exe's for some impressive physics and collide demos. Includes source in C++.


Haramanai(Posted 2005) [#11]
Of course I am going to use the new TVector. I don't have any sugestion so far (time will tell).
And yes I am looking in PollyColly rigth now and it looks really good but I don't have c++ background so... it will be hard for me.


Shagwana(Posted 2005) [#12]
Let me make this thread a sticky for you!. But if I see lack of intrest (ie dead!) I will un-sticky it, unless its complete!!. Good luck :).


Tibit(Posted 2005) [#13]
And yes I am looking in PollyColly rigth now and it looks really good but I don't have c++ background so... it will be hard for me.
Same here. Don't miss the excellent tutorial (in html) that comes along.

@Shagwana, Thanks. Note that I intend to create a new thread as we progress (with links to old ones). This is so the discussion can be focused on the most recent updates, questions and problems.

I'll work on a base for the Line Type now, which will be based upon your Haline2D and TVector.

(I'll update the full TVector with Cartesian system in a moment)


Shagwana(Posted 2005) [#14]
@Shagwana, Thanks. Note that I intend to create a new thread as we progress (with links to old ones). This is so the discussion can be focused on the most recent updates, questions and problems.
No problem will sort as you go along.


Haramanai(Posted 2005) [#15]
I had maded some progress in HALine2d
here is the type with an example in reflection


I will try to find out a good way for pollygons (from PollyColly and from Luke's p2d code and mathworld)


Tibit(Posted 2005) [#16]
I'll take a look at it right away.

Updated:
Example and Debugger for the VectorLib


Also note that I change Tvector to Vector2D. I feel that would be the best as there is a big chance someone will make a Vector3D one day.


Haramanai(Posted 2005) [#17]
Wave I think it will beter If you put the latest vertions of the Mod and the examples on your First (or the second) post so the newcomers can get them without traveling over the topic.


Tibit(Posted 2005) [#18]
I agree, will do that.

I have been starting to work out how the full library architecture might look like. The idea I'm following right now is that our Line2d (as I call the Line-Type) will inherit Vector2D and Vector2D will inherit TShape.

Our TPhysicsObject will have a field called CollisionForm:TShape

Because All our shapes will inherit Tshape this would mean that Box,Line,Circle,Vector and Polygon all can be put in there. Also to take it one step further Polygon will be based upon Line2D and Box and Triangle will simple be special cases of the Polygon- not types of their own.

The final implementation (for the onces using the library) may be something like this:



A more final plan that this needs to be worked out before we proceed much further.

And Haramanai, your line vs line example's reflected line seems to not display or display backwards if you move the lines around (try having the green line vertical for example). Perhaps a bug there?




Tibit(Posted 2005) [#19]
Here is polygon code for everyone to play around with.

Run the demo to see some boxes from polygons collide. Nothing fancy. We can probably use parts of it.



LarsG(Posted 2005) [#20]
Just a suggestion might be that you can have a vector type of Doubles in addition to normal Floats...
(there might be someone with the need for high value calculations)


Tibit(Posted 2005) [#21]
Haramanai here is my implentation of the Line2D (mostly) following the overall plan (2 posts above). If you like it and think it will work together with everthing else please expand the type with your methods from haline2d. Try to use Vectors as much as possible instead of X,Y fields (I think that gives it more flexibility and readability).

I must say we have come a good way so far.


Also Updated to Vector Library to use doubles instead of floats - Thanks LarsG


Haramanai(Posted 2005) [#22]
Ok I puted the methods in the Line2d

Here it is the New Line2d


and here the reflexion sample

The red line is the line that reflected

EDIT: I think we must make the create function in a differnt way so we can use create() and get the minimum.

For example
Function Create:Vector2D( X! = 0, Y! = 0 )
	
		Local Vector:Vector2D
		Vector = New Vector2D
		
		Vector.X!  = X!
		Vector.Y!  = Y!
		Return Vector 
		
	End Function


EDIT: How to use the reflection demo
keys: 1 puts the starting point of red line to the mousecursor
2 puts the end point of red line to the mousecursor
3 puts the starting point of green line to the
4 puts the end point of green line to themousecursor

what it do: Think that some think will travel from red's start point to the end of it. but then it collides to the green line and bounce so the real position of this travel it's the end of the new green line

EDIT4: The problem is from the colideLine Method created by Warpy in this post : http://www.blitzmax.com/Community/posts.php?topic=52384

I fixed it in a way. I changed the D2x to 0.0001 if it is 0. It's not perfect but this is what I have right now


Tibit(Posted 2005) [#23]
Great Work!

The reason the create method has no default values is that you are supposed to use the function CreateVector() if you want to have defaults. The library itself uses the method and then you also have to specify both X and Y, for security reasons.

We would really need someone who knows C++, that would save us countless hours. Converting the polygon code from that library.

What did you think about my "collidionPlanes" idea?

We should really try to make a simple demo and show how a object (let's start with a circle) would slide and bounce against some lines. Where you can set the Friction and Bounce parameters.

The worst thing, I really hope making "demos" will be so much easier when we have the GUI mod..

RE:EDIT2 ok, I didn't get a null error, what I meant was the wrong reflection I got when I took the end point and put it first (then it reflects through the other line instead of away from it).

Also I would like to make a simple map editor (poly/line editor) so that we can build physics demos. Yet that would also "require" the GUI module..

I think our first priority should be a nice demo that shows off EVERY ascpect of the library. With loads of options and switches. Having a really good testing enviroment would allow us to test new features much easier and without having to rely on teori. I'm afraid we will do a lot of work that we have to redo because we edit a major thing.

One thing that came to my mind (sorry) was the Line2D. I think we would benifit from having fields liek this:
StartX, StartY
Vector:Vector2D 'The Line vector , From startXY to EndXY
EndX,EndY
Normal:Vector

Because this would mean that checking the lenght of the Line would mean checking the vector. Also the angle would follow. The best thing in my opinion of using the Vector2D type as much as possible (instead of rewriting code) is that if someone comes up with a better or more efficient way to calculate basic vector stuff then ALL of the library/module will benefit. And you never know what will happen in the future, only time will tell =)


Tibit(Posted 2005) [#24]
I will soon create a new thread to sort the project up a bit.

We still have a lot of unanswered questions about the projectplan that needs to be discussed further.


Haramanai(Posted 2005) [#25]
I found the problem with the collideLine Method and I fixed in a way. I updated my post with the new vertion.

I cannot find your collidePlanes. pls point them to me.


Tibit(Posted 2005) [#26]
I haven't written anything involving them yet. It's just a design idea. Implementing it shouldn't be too hard. We can simple have one TList for every plane. The planes are just a way to make collision checks easier and simpler for the end-user (or so I hope).

See my post on "full library architecture" (8 posts above)

To make the line bounce and slide all information we need is in this topic:
http://www.blitzbasic.com/Community/posts.php?topic=52511
All thanks to Warpy!


altitudems(Posted 2005) [#27]
This is a little off topic but here is a simple Circle-Circle Collision routine for you to use.




Tibit(Posted 2005) [#28]
Altitudems, this is not off topic at all, it is really good. Will be used.

This is cool. With the circle code and our line2D code combined we already have all physics we would need for a pinball game.


Matt McFarland(Posted 2005) [#29]
Awesome :)


IPete2(Posted 2005) [#30]
I wish I was less busy so I could even get a chance to try the examples out above.

I'm very busy just now trying to finish of a couple of projects, but hopefully I'll have some time at some stage in the run up to Christmas (I hope!).

In the meantime I'll keep an eye on this thread for info.


IPete2.


Tibit(Posted 2005) [#31]
Good to hear ;)

I'll soon make a fresh thread and start he project for real. I think we should have the project work threads in Moudle/Tweaks forum instead.


This does not seem to work, I'm trying to get the line normal, Method lies in Type Line2D:

Method CalculateNormal()
'Both these ways should work (WARPY)
'But none of them do!?

' Local Angle# = ATan2( X, Y )
' Normal.X = Cos( Angle + 90 )
' Normal.Y = Sin( Angle + 90 )

'OR

Normal.X = 1
Normal.Y = - X/Y
'Normal.Normalize()
EndMethod



MOST IMPORTANT:

How to handle collisions?
The library will take care of most of the work for the user. The user only needs to create som eCollisionplanes, fill them with objects and then set the collisionresponse for each plane against each other plane. In other words this determines how the Shots collides with walls, how they collide with Ships or ships with sheilds. The result would be that a Plane for each response type will be required. One object is recommended to only be in one plane.

Example code not runnable (See the idea)
Type Line2D

	Method CircleCollide( Circle:Circle2D ) 'Line or Vector vs Circle
		
		
		'All calculations is done here
		'Check is they collide
		If Collide Then Return True	
		
		
		'Most times we want to know more than that they just collided:
		
		'The intersection point
		'The reflecting vector

		'This is optional and is done after we know they collided
		
		'All data of the collision needs To be accesible
		'to further functions that deals with collision response
			
	EndMethod

	Method Collision_GetIntersection( X Var , Y Var)
		'.....
	EndMethod

	Method Collision_GetSeparationVector:Vector2D()
		'.....
		'Usually you use this to alter you position back - so that you do not collide
		'Then depending on elasticy and friction we alter the response.
	EndMethod

EndType

Type MaxPhysicsObject

	Method Collision_ApplyResponse()
		'Alters your speed and your location after a collision
	EndMethod
	
EndType


Type Circle2D Extends MaxPhysicsObject

	Method LineCollide( Line:Line2D ) 'Circle vs Line
		
		Line.CollideCircle( Self )'Call the actuall Line vs Circle method which lies in Line2D
						
	EndMethod
	
EndType



altitudems(Posted 2005) [#32]
How is this?



altitudems(Posted 2005) [#33]
Do you think we could eliminate a lot of work/confusion and start by porting over the PollyColly code previously mentioned?


Tibit(Posted 2005) [#34]
Altitudems, yes that is a very good suggestion, Actually I was playing around with your circle demo in a similar fashion.

This is with planes (I will add more later) :

Strict

'List of collision objects
Global CollisionObjectList:TList = CreateList()

'Define collision response types
Const COLLISION_STATIC:Int = 0
Const COLLISION_DYNAMIC:Int = 1

'Our base collision object
Type TCollisionObject
	Field ResponseType:Int
	
	Field Shape:TShape
	
	Field Position:TVector2
	Field Velocity:TVector2
	Field Acceleration:TVector2
	
	Field LastColliders:TList
	Field LastSeperationVectors:TList
		
	Method New()
		CollisionObjectList.AddLast(Self)
		Position = New TVector2
		Velocity = New TVector2
		Acceleration = New TVector2
		LastColliders = CreateList()
		LastSeperationVectors = CreateList()
	End Method
	
	Method Destroy()
		CollisionObjectList.Remove(Self)
	End Method
	
	Method TestForCollision()		
	End Method

	Method Update()
		Velocity.AddVector(Acceleration)
		Position.AddVector(Velocity)
	End Method
	
	Method Response( Collider:TCollisionObject )
	' Check collision response
	'1. Circle vs Circle
	'2. Line vs Line
	'3. Circle vs Line
	'4. Polygon... 5,6
		Select Self
			
			Case Circle2D(Self)
			
				Select Shape
					Case Circle2D(Collider)
						CircleReponse()'In this case Circle vs Circle Only
					Case Line2D(Collider)	
						LineReponse()
				EndSelect
				
			Case Line2D(Collider)
				
				Select Shape
					Case Circle2D(Collider)
						CircleReponse()
					Case Line2D(Collider)	
						LineReponse()
				EndSelect		
			
		EndSelect	

	EndMethod
	
	
	Method CircleResponse()
        'Convert lists to arrays to avoid miss linkage
        '(there may be a better way)
		Local ColliderArray:TCollisionObject[] = LastColliders.ToArray()
		Local SepVectorArray:TVector2[] = LastSeperationVectors.ToArray()

		For Local I:Int = EachIn ColliderArray
			'Do collision response / seperate objects
			Select ResponseType
				'We are static (won't move)
				Case COLLISION_STATIC
					'Collider is dynamic and will move
					If ColliderArray[I].Response = COLLISION_DYNAMIC
						'Seperate obects by moving collider along seperation vector
						ColliderArray[I].Position.X :- SepVectorArray[I].X
						ColliderArray[I].Position.Y :- SepVectorArray[I].Y
					End If
				'We are dynamic and will move
				Case COLLISION_DYNAMIC
					Select ColliderArray[I].Response
						'Collider is dynamic and will move
						Case COLLISION_DYNAMIC
							'Both objects are dynamic so
							'seperate them by moving them equaly
							Position.X :+ SepVectorArray[I].X *.5
							Position.Y :+ SepVectorArray[I].Y *.5
							ColliderArray[I].X :- SepVectorArray[I].X *.5
							ColliderArray[I].Y :- SepVectorArray[I].Y *.5
						'Collider is static (won't move)
						Case COLLISION_STATIC
							'Seperate obects by moving us along seperation vector
							Position.X :+ SepVectorArray[I].X
							Position.Y :+ SepVectorArray[I].Y
					End Select
			End Select
			'Clear our lists
			LastColliders.Clear
			LastSeperationVectors.Clear
		Next
	EndMethod
	
End Type


'The user type
Type TTank Extends TCollisionObject

	Field Weapon = 2

	Method New()
		Shape = New TCircle2D
	EndMethod
		
EndType

	Local Tank:TTank = New Tank
	Local Tank2:TTank = New Tank	
	Const TANK_PLANE = 1 'Collision Plane for Tanks
	Const WALL_PLANE = 2 'Collision Plane for Walls	
		
	Tank.AddToPlane( TANK_PLANE )
	Tank2.AddToPlane( TANK_PLANE )	

	Local WallA:TWall = New TWall
	Local WallB:TWall = New TWall
	Local WallC:TWall = New TWall
	Local WallD:TWall = New TWall			

	'Another way to add objects
	AddPhysicsObjectToPlane( [WallA,WallB,WallC,WallD], WALL_PLANE )

	'Or we could do it like this:
	'Will add ever Wall created so far to the WallPlane (id = 2) or plane 2
	AddPhysicsObjectToPlane( Wall.List.ToArray[], WALL_PLANE )
	
	SetDynamicPlane( TankPlane )'All Tanks will bounce and slide
	SetStaticPlane( WallPlane )	'All Walls can't move
		
	While '---
	
		'Only checks if it collides
		'See WallPlane and TankPlane as Lists with objects
		If Collision( [WallPlane,TankPlane] ) 
		'Runs the Collison method in every object
		'First selects which shape the object has then
		'it check for collision
		'So it doesn't matter if our tank is a circle or a line or a polygon
		
			Print "Collided"
			For Local Tank:TTank = EachIn CollisionList 'All Tanks that collided
				
				Tank.Armor:-1
				If Tank.SheildActivated = True
					Tank.Elasticy = 1
					Tank.Friction = 0
				Else
					Tank.Elasticy = 0
					Tank.Friction = 0.5					
				EndIf
							
				Tank.Response()'The Tank is Dynamic so this alters velocity and position		
									
			Next
			For Local Wall:Twall = EachIn  CollisionList 'All Walls that collided
				'Something like this
				Local PositionOfImpact:Vector2d = Wall.GetImpactLocation()
				CreateExplosionAt( PositionOfImpact , ExplosionType("Nuclear")  )
			Next
		EndIf
			
	Wend'----
	

'A type of collision object
Type TCircle2D
	Method CollideCircle()
		'Test for a collision between each object in list
		For Local Collider:TCollisionObject = EachIn CollisionObjectList
			'Make sure not to check collisions with self
			If Collider <> Self
				'Check for collision based the the type of object
				If TCircle2D(Collider)
					'Test for collision
					'If objects collide
					If CollisionIsFound
						'Add this collider to the collider list
						LastColliders.AddLast(Collider)
						'Find the seperation vector
						Local SeperationVector:TVector2 '= Shortest Path to Seperate Objects
						'and add it to the list 
						LastSeperationVectors.AddLast(SeperationVector)
					End If
				End If
				'Repeat for each type of object
			End If
		Next
	End Method
End Type


I think we should separate shapes and Collison objects. Because you might want to check a circle against a line without having the circle being an actuall object, for example the mouse pointer. Anyway it feels more flexible if any object can have any shape! And there is no problem changing the shape while we run the game :)

See the above code (based upon yours). What do you think?
Please add/change/suggest more. I'm open to anything.


Do you think we could eliminate a lot of work/confusion and start by porting over the PollyColly code previously mentioned?

Indeed. That would be a super start. Do you know C++?


Tibit(Posted 2005) [#35]
I mean I have never manage to successfully add rotation and torque to a game. And the polly code demos is so damn cool. Converting it would save a lot of head acke, if I knew C++ I would alread have started that.


Haramanai(Posted 2005) [#36]
I found a problem in the Line2d I posted above to the function createParallel and I fixed it.(I Edited the post)

This may help for the circle Line collision case
(I found it in the codearchives)
Function MinDistPointLine#(px#,py#,x1#,y1#,x2#,y2#)

	If x1 = x2 And y1 = y2 Then Return PointToPointDist(px,py,x1,y1)

	Local sx# = x2-x1
	Local sy# = y2-y1

	Local q# = ((px-x1) * (x2-x1) + (py - y1) * (y2-y1)) / (sx*sx + sy*sy)

	If q < 0.0 Then q = 0.0
	If q > 1.0 Then q = 1.0

Return PointToPointDist(px,py,(1-q)*x1+q*x2,(1-q)*y1 + q*y2)
End Function


I still trying to find out a way to handle poly poly collision but sadly with no luck. I will still searching.
No luck to the convertion of methods in polycolly.(I just losted the game in the first tutorial shame on me)
I found an nPoly lib maded for blitz in the showcase it even have it's entry to the number 9 of the Blitznews.
Here is the post : http://www.blitzmax.com/Community/posts.php?topic=36003&hl=npoly
but you will find out that we cannot take it and look throu it. The code of nPoly may solve some of the problems right now.
After all this concept it's a really good learning curve for me and I am glad thinking that I am part of it.

Edit: And another think to have the poly poly collision we must find a way to imliment this method : http://gpwiki.org/index.php/Polygon_Collision
This is the fastest and the mostly used.


Haramanai(Posted 2005) [#37]
Edit: My fault. This was not good enought. I will posted again if it will work as it must work. Sorry about that I will make more tests before posting.


altitudems(Posted 2005) [#38]
@Wave
I am only slightly familiar with c++, I just look up what I don't understand. I have allready started converting some of the code from PollyColly. Here is what I have so far:

Vector.bmx : Ported From Vector.h

I'll post more soon.


altitudems(Posted 2005) [#39]
Aside from the pollycolly code I posted a working polygon collision lib a while back.

http://www.blitzbasic.com/Community/posts.php?topic=46332


Tibit(Posted 2005) [#40]
That vector part you converted has a lot of functions we don't have in our Vector2D, so great job. Now our vector library base is very solid. I'm looking forward to see more.

I'll add that vector lib to our Vector2D tomorrow and altitudems, you have to promise you use the main vector2D library, when/if you manage to convert more of the pollycode.

Haramanai, good job on the VectorLib. I'll combine it all in the Vector2D and start a new threat for the project tomorrow.

Meanwhile we need to decide on how it should work for the end user and also how we are going to split up the code in several files/types so that it get's both modular; easy to build on in the future and that we finilize the core; so that we can start making a simple tutorial /w examples.

Remember the end goal is something like the polly code. I'm also writing a tutorial for newcomers.

Don't forget we need any fancy vector example anyone could have. My idea is to combine several demos into one big fat demo.


altitudems(Posted 2005) [#41]
you have to promise you use the main vector2D library

I won't promise you that, because if I did it would make the conversion much harder. The vector lib I posted is a strait line for line conversion of the PollyColly code. Once we have the PollyColly code completely converted then we can think about adding/modifing the vector lib.


Haramanai(Posted 2005) [#42]
My post above was not good and I edited.
altitudems good job with polygons.


Tibit(Posted 2005) [#43]
@Altitudems. You are right. Better to get it working first.

I'll try to structure our project a bit and finaly create some new threads.


Tibit(Posted 2005) [#44]
Is there a way to fill and texture a polygon? vertices?


tonyg(Posted 2005) [#45]
Textured polys


Tibit(Posted 2005) [#46]
I can't find the main loop in PollyCode..

If C++ is anything like java then this is the start of the program:


void main(int argc, char** argv)
{
	//--------------------------------------------------------------------------
	// OpenGL / GLUT init
	//--------------------------------------------------------------------------
    glutInit( &argc, argv );
	glutInitDisplayMode		(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);
	
	glutInitWindowSize		(width, height);
	glutInitWindowPosition	(0, 0);
	glutCreateWindow		("Tutorial 2 - Extending the method of separating axis for collision response");
	
	glPointSize(3.0f);
	glEnable				(GL_BLEND);
	glBlendFunc				(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
	glDisable				(GL_DEPTH_TEST);
	glDisable				(GL_LIGHTING);
	
	glutDisplayFunc			(Display);
	glutReshapeFunc			(Reshape);
//	glutIdleFunc			(Idle);
	glutTimerFunc			(0, Timer, (int) 100.0f / 60.0f);
	glutPassiveMotionFunc	(PassiveMotion);
	glutMouseFunc			(Mouse);
	glutMotionFunc			(Motion);
	glutKeyboardFunc		(Keyboard);
	glutSpecialFunc			(ExtKeyboard);

	Init					();
	glutMainLoop			();
}



glutMainLoop(); // I this is it.. But where does this function call go? What file? What function? The dll?

EDIT
Tony, thanks. A nice addition to the physics lib would be a method that draws the polygon with textures. "at the moment it uses trianglefans" - Does that mean the textures will break if not perfect squares or triangles?


sczerbiak(Posted 2005) [#47]
take a look at this : http://www.aidspan.org/alec/physical/index.htm

Physical is a game creation system based on the foundation of an innovative 2D physics engine. Its main features include:

* Incorporated functionality for graphics, keyboard handling, and game flow

* A framework that provides a direct mapping from game design to game programming

* Interchangeable, reusable parts

o Interactive game elements from any game can be used in any other game

o This includes reusing not just model and image files, but the actual dynamics that make a plane fly or a gun shoot

o This allows for the creation of a common library of freely downloadable game elements: the Repository

* An included object editor

* A new kind of physics engine that naturally handles object deformation - things can bend, break, flow, and explode


Diablo(Posted 2005) [#48]
@wave
i think it is a call to a libary function - it says - requirements : GLUT library, OpenGL support.

EDIT: try This


Tibit(Posted 2005) [#49]
Sergio Thanks! Great link will help a lot in organizing and setting up our engine.


@Diablo
Ok now I get it. The Glut library uses some Callback Registration Philosophy. And what you do before the mainloop function is to thell Glutt the names (pointers?) of the functions you are useing as display/update and so on.


Shagwana(Posted 2005) [#50]
Thread continued right here


Tibit(Posted 2005) [#51]
@Shagwana
Can I have the project in Module Tweak forum instead?
It's going to be ~5 topics

And as of the moment it is created it is going to stay open to modification/tweaks from anyone.


Shagwana(Posted 2005) [#52]
5 topics?

My thinking is that all these community projects should be in the same place (so thats why its over there near fmod one!)


Tibit(Posted 2005) [#53]
I will have one here to enlist people and tell them about the project (Link to the main topic): It should be a Locked topic.

Then in module tweaks I have all the "work" topics

One for each part:
Structure and News (Overall Suggestions)
Examples and Demos (For testing)
Completed Parts (The most up to date code)
Working Parts ( including each of the types:
Vector2D
Line2D
Polygon2D
Circle2D
PhysicsObject )

That makes up for five topics in total, one here and four in Tweaks.

Or can we have whole new forum? (for community projects)


Tibit(Posted 2005) [#54]
To clearify
The "Working parts" is the parts we work on: It should be "In progress". This is where everyone adds code (actual work and not ideas). This topic needs to be cleaned up once in a while and the result will be in the "Completed Parts" topic.

The idea and benifit with this system is that newcommers will have an easy time. They will see what the project is about. Whan they can do and what need to be done. They can also see what is already done. All without the need to read through 100's of long posts.


Shagwana(Posted 2005) [#55]
Well i dont wish to be cluttering up the sticky area of the forum with multipul threads on the same topic. So please put links in your sticky one to the relative threads you have planned.

You sure you need 5 threads to do what you want?. Fmod managed it all with 1 thread!.


Tibit(Posted 2005) [#56]
Fmod managed it all with 1 thread!.

Yes, but is it worth the cost? See this thread. We haven't even started the project and even on my connection the page takes several seconds to load. And no sane person would read through everything so that they are up-to-date. How are the FMod project going by the way?
To be honest I don't know how they manage, perhaps their project is smaller/simpler?

Can you move my "MaxPhysics Community Project : Main" topic back to the Tweak forum and I will create a new one here as I planned from the start. I do think that is the best way to do it, but I'm always open for suggestions.

EDIT
I'll use the current main, no problem. But I will create the rest of the topics I "need" in the tweak forum if that is ok.


Diablo(Posted 2005) [#57]
@wave
Dont know if this will help you. its some help functions and types to draw textured polygons (doesn't work with directX at the mo)

DrawPolly

You will need to have done this first tho (and added the openGl code) (thx tonyg - didn't know about this cool code)


Tibit(Posted 2005) [#58]
Nice, is there a way to tile or cut the texture instead of scaling or distorting it? In case you want to make a poly map for example.