MaxVerlet Test

BlitzMax Forums/BlitzMax Beginners Area/MaxVerlet Test

Chroma(Posted 2011) [#1]
Time for a proper test. Collision is working. It's not the best but it's doing the trick. If anyone would like to contribute to this please feel free. Any comments or source code suggestions to improve this would be great.

Here's what you need.

Vec2.bmx


MaxVE.bmx:



And here's the test program:



Qcat(Posted 2011) [#2]
Hi!

i have been having a mess around with the code and it seems to be working quite well. There seems to be in issue with the collision Code I have attached a screen shot below.



I will have a good look and see if I can finger it out a fix in the next few days!

Other than that it all seems to be going very well!

Adam


Chroma(Posted 2011) [#3]
Yeah it's got to do with the collision reaction only working one way at the moment. The shape that gets hit doesn't react yet. I'm still trying to figure that one out but I know it has to do with get a line normal etc blah blah lol.

If you set the CreateVerletCircle segments to about 12 or 16 it's really fun to play with. :)

Btw, thanks for taking an interest in this. It really helps when someone else is posting feedback and helping out.

Last edited 2011


GfK(Posted 2011) [#4]
For the record - this isn't a beginner's subject.


Chroma(Posted 2011) [#5]
For the record - this isn't a beginner's subject

You're right. I never should have started this thread.


Anyways, some things that aren't working correctly/To Do List:

1. Constraint "stiffness". I envision a value from .01 to 1. With 1 being stiff as a board. It seems any value over .5 makes the resolve part blow up.

2. Collision needs mass taken into account and also reflection.

3. Angular constraints. Still looking into this one.

4. Getting a shapes rotation value. Basically all you need to have is two points that are vertically aligned and then return the angle between them. But if you have really weird shapes....mmhmm.

5. All the collision really needs is to put in a collision reaction for the object that is getting penetrated by a point. Then maybe some bounding box checking to help speed it all up. For the object colliding with something it's easy. You just back the point that collided back up to the previous position and the object reacts naturally. But the object that gets hit....

6. A way to Parent a shape to another shape just by location alone. Useful for attaching wheels to cars etc.

7. Shape rotation. I've seen the code somewhere. Just have to find it.

8. Proper restitution/friction. And a way to assign a shape a friction value so things can be slippery (ice) or have lots of traction (pavement).

Last edited 2011


Chroma(Posted 2011) [#6]
Here's a LoadShape function that will load your own custom verlet shapes that are saved with .mvs extension (mvs = MaxVerletShape).

' MaxVerlet :: LoadShape
Function LoadShape:VShape(mvsFile$, scale#=1.0, x#, y#)
	If Not FileSize(mvsFile) Return Null

	Local s:VShape = New VShape

	' Parse MVS file
	Local io:TStream = ReadFile(mvsFile)

	Repeat

	Local dat$[] = ReadLine(io).Split("=")
	Local key$ = dat[0]
	dat = dat[1].Split(",")
	Local i, val#[]
	For i = 0 To dat.length-1
		val :+ [Float(dat[i])]
	Next

	Select key

		Case "point"
			s.AddPoint(x + val[0] * scale,y + val[1] * scale, val[2])

		Case "autoconstraintedge"
			If Int(val[0]) s.AutoConstraintEdge()

		Case "constraint"
			s.AddConstraint(s.point[Int(val[0])], s.point[Int(val[1])], Int(val[2]))
			

		Default

	End Select

	Until Eof(io)
	CloseFile(io)

	s.active = True

	Return s
End Function



Here's what a simple box.mvs file looks like.
point=0,0,1
point=1,0,1
point=1,1,1
point=0,1,1
autoconstraintedge=1
constraint=0,2,1
constraint=1,3,1


Last edited 2011


Chroma(Posted 2011) [#7]
The LoadShape function works great.

I think it's time to actually start trying to build a mini-game Qcat. Maybe something like "Crush the Castle". The only thing we need to do before that can happen is to add line to line collision and bounding box checking. And add joints and hinges so we can build a catapult.


ima747(Posted 2011) [#8]
This is looking awesome. Can't wait to find time to play with it!
A) Fingers crossed you roll a MOD out of this when you're happy with the results
B) Having no experience with vertlets, wondering how hard it might be to convert them for 3D (since they looks like a pretty easy to understand implementation of physics from my glances through this...)


Qcat(Posted 2011) [#9]
Wow!

Things are going really well with this I will happily help out how ever I can. I have not had chance to try the load object code out has yet. (Hectic day we have a new database rollout at work tomorrow!)

It might be handy to add a way to attach sprites to an object. Perhaps it might be worth adding some kind of tether point. And then using good old cos and tan to work out than angle!

A little angry bird’s castle destroying sounds like a fun little project to me!

Last edited 2011


Chroma(Posted 2011) [#10]
I started working on a simple shape editor. Just a small windowed app that lets you plot points in succession and throw in edge and support constraints. Then export to .mvs file so they can be loaded directly in. Will post it soon.

Btw, for the .mvs file, here's what each number is.
point=x,y,mass
autoconstraintedge=1   'this automatically outlines the shape with edge constraints
constraint=point1,point2,mode   'where mode is 0 for edge or 1 for support constraint
Edge constraints (mode 0) are used for collision. Be sure to use support constraints (mode 1) when adding inner support constraints.
Also, try to plot points around 0,0 with 0,0 being center. This is will automatically be taken care of in the editor.

Last edited 2011


Qcat(Posted 2011) [#11]
a shape editor is a must! i am hoping to have a few days off work next week so am planing to have a play around with the code you have posted so far.

how are things going at the moment?


Chroma(Posted 2011) [#12]
It's going pretty decent I suppose. Haven't had much anything new to show in the last few days. I really want to get the collision stuff done. I was thinking about how to complete it. Tell me what you think of this. The PointInShape function returns True when a point enters a shape. But, it doesn't do anything except move the offending point back to it's previous position, which is fine for dealing with collision for the offending shape. But what about the shape that was collided into? At the exact moment of collision. If you draw a line from the current point position to the previous point collision, it will intersect with a line on the shape that was collided in to. So to find out what line was hit, you do a lines intersect test. This will allow for a reaction for the collision to the shape that was hit! I just have to get the code in place and start tweaking. I believe this might allow for vertical stacking of one block on top of another. Maybe... But the theory is sound. I think it will work.

Hopefully I'll have time to test this out later this morning.


Qcat(Posted 2011) [#13]
The logic of that method sounds fine to me! But the only way to really find out is to give it a try.

Speed is probably a slight issue and I was thinking about how you would factor delta time in.


Chroma(Posted 2011) [#14]
Yep that's true. I've researched how to put the mass into the algorithms too so that will show up in the code prolly next time around. But, working 12 shifts at working right now sooo...time will be short until Sunday. :(