Behaviour v0.1
Copyright Johan Jansson <d96-jja@nada.kth.se>

Sketchy documentation:

Introduction:

	Behaviour is a simulator program which simulates some
physical laws. It builds on two basic primitives: the object
and the connection. An object has, at the least, a position,
while a connection has at least an orientation. A connection's
orientation is produced by connecting two objects. Aside from
these basic properties, objects and connections have several
other properties listed and explained below. Determining the
state of all objects are several laws, also listed and
explained below. The simulation is done through a stepping
process. Given a state and a timeslice, it can calculate the
state for the current time + the timeslice.


Interaction:

	Right now, the only way to interact with Behaviour is
through datafiles and the primitive graphical frontend
(made with OpenGL). The datafiles are expressed in a simple
human readable language (the language will probably be redesigned
in future versions). It's quite self-explanatory, but I have
included some documentation below. The frontend is also quite
easy to understand if you experiment a little. Here is a little
help table:

Mouse:
	button 1:		orbit the camera around object-space origo.
	button 2:		drag objects around.
	button 1+2/3:	rotate object-space around object-space origo
					with regard to the camera's z-axis.
					( this sounds quite bad, but I find it
					quite intuitive, at least for the type
					of scenes I have done )
Keyboard:
	q/w:	see mouse button 1.
	a/s:	see mouse button 1.
	z/w:	see button 1+2/3.
	
	(keypad is recommended for the following keys)
	1/3:	move z-wise in camera-space.
	4/6:	move x-wise in camera-space.
	8/2:	move y-wise in camera-space.
	

Properties and laws:

	object properties:

	position
	velocity
	mass
	radius
	damp
	k
	tolerance
	gsource		(gravity source flag)
	grecipient	(gravity recipient flag)
	id

	connection properties:

	length
	damp
	k
	tolerance
	id

	laws:
	
	gravity
	spring law
	air resistance
	collision

	explanation:
	
	The gravity law is the standard Newtonian gravity law:
	F = G*(M*m)/r^2
	All objects have flags to determine how they take part
	in this.

	The spring law is Hooke's law with the addition of damping:
	F = k*(l+e) + damp * evelocity, where "e" stands for elongation
	and "l" stands for wanted length.
	If the force on the connection exceeds it's tolerance, the
	connection is broken.

	Air resistance:
	F = air * velocity^2 * r^2
	
	Collision is handled by adding a connection between two objects
	when they intersect. The parameters for the connection are
	specified for each object, and the collision connection is
	the average of the parameters of the colliding objects.


Language:

	The datafile language consists of the following keywords
	(explained where needed):

		object
		connection
		global
		graphics
		camera
		window
		triangle
		sphere
		line
		vector
		dt (timeslice size)
		air (air density)
		position
		lookat
		up
		orientation
		velocity
		k
		damp
		tolerance
		length
		radius
		id
		mass
		gsource
		grecipient
		connect
		mount
		template
		force
		scale
		wireframe

	constants:
		integer
		real
		boolean

	structure:

		The language is structured by using blocks.
	
		block:
		keywords
		{
			blocks OR constants
		}	

		blocks:
		block OR blocks

		constants:
		constant OR constants
		
	For a reference of the valid blocks, please refer to the
	example datafiles. Standard C-style comments work too, ie. /**/.
	
	NOTE: The language will probably be redesigned in future versions.
	

	Correctness:
	
		I haven't done any real testing to see if the simulations
	correspond to Newtonian physics or the real world. However,
	the general behaviour of the simulations looks quite realistic,
	and this has been the aim. Hopefully I will achieve some level
	of correctness, either in this version or future versions.
	
	Usefulness:
	
		Behaviour has no real use yet, except as a toy. Two potential
	uses are for animation and education. As an animation tool, it
	could optimally reduce the animation process to making a single
	frame, and letting Behaviour calculate the animation. Realistically,
	it could maybe be used for creating trajectories and behaviour of
	singular dynamic objects, for example elastic materials and
	structures, or crashes and situations where objects break up into
	pieces. As an educational tool, it could be used to create experiments
	which are otherwise hard or expensive to set up, or where it is hard
	to observe what is really happening.
	
	Comments on the model:
	
		Behaviour's model builds on only two very basic primitives,
	which I think can lead to very powerful results. Instead of having
	a box primitive, one can build a box out of many connected objects,
	and with this gain a dynamic box which can bend and be torn apart.
	I have tried to mimic the real world in this, to have objects be
	somewhat like molecules, and connections like chemical bonds. Instead
	of having one object per molecule, one can aggregate many molecules
	into one object, and expect it to behave roughly as the cluster of
	molecules would have, being separated. To mimic a ball, one could use
	only one object to get a decent model. Of course it has limitations,
	for example, it has no orientation, since single objects don't have
	this. We could take 8 objects and connect these to make a cube. If we
	compress this cube we have a hybrid between a ball and a cube, but
	which has orientation, and behaves approximately as a cube with
	rounded corners would. From here, we can either structure objects in
	a spherical shape to get a more ball-like shape, or we can make corners
	of increasingly smaller objects to get a cube. I think it is much easier
	to reason in these ways instead of trying to increase the complexity
	of the model to suit one's needs.
	
	Limitations of the model:
	
		There is one basic law which is missing, which shows in my
	examples, namely friction. I think I have a solution for this, but
	I'm not sure friction fits so well with the current model. If two
	objects would collide in any way other than head on, it is natural
	to think they would start to rotate in addition to changing trajectory.
	However, the current model does not allow this.