Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • Alexandre.Meyer/m1if37-animation
  • Alexandre.Meyer/m2-apprentissage-profond-image
  • Alexandre.Meyer/m2-animation
  • Alexandre.Meyer/hugo-web-minimal
  • Alexandre.Meyer/lifami
  • Alexandre.Meyer/lifapcd
  • Alexandre.Meyer/www
  • Alexandre.Meyer/lifstage
8 results
Show changes
Showing
with 0 additions and 1444 deletions
#pragma once
#include "Stdafx.h"
#include "AABB.cpp"
#include "Body.cpp"
#include "BodyDef.cpp"
#include "Joint.cpp"
#include "JointDef.cpp"
#include "Contact.cpp"
namespace Box2D
{
namespace Net
{
public ref class World
{
b2World *world;
public:
World(AABB^ worldAABB, Vector^ gravity, bool doSleep) : world(new b2World(
worldAABB->getAABB(), gravity->getVec2(), doSleep)) { }
~World()
{
delete world;
}
/// <summary> Create rigid body from a definition </summary>
Body^ CreateBody(BodyDef^ def)
{
return gcnew Body(world->CreateBody(def->def));
}
///<summary>
/// Destroy rigid bodies. Destruction is deferred until the the next call to Step.
/// This is done so that bodies may be destroyed while you iterate through the contact list.
///</summary>
void DestroyBody(Body^ body)
{
world->DestroyBody(body->body);
}
/// <summary>
/// The world provides a single ground body with no collision shapes. You
/// can use this to simplify the creation of joints.
/// </summary>
Body^ GetGroundBody()
{
return gcnew Body(world->GetGroundBody());
}
void Step(float32 timeStep, int32 iterations)
{
world->Step(timeStep, iterations);
}
Joint^ CreateJoint(JointDef^ def)
{
return gcnew Joint(world->CreateJoint(def->def));
}
void DestroyJoint(Joint^ joint)
{
world->DestroyJoint(joint->joint);
}
property IList<Body^>^ Bodies
{
IList<Body^>^ get()
{
List<Body^>^ list = gcnew List<Body^>();
for(b2Body *body = world->GetBodyList(); body; body = body->GetNext())
list->Add(gcnew Body(body));
return list;
}
}
property IList<Joint^>^ Joints
{
IList<Joint^>^ get()
{
List<Joint^>^ list = gcnew List<Joint^>();
for(b2Joint *joint = world->GetJointList(); joint; joint = joint->GetNext())
list->Add(gcnew Joint(joint));
return list;
}
}
Joint^ GetJointList()
{
return gcnew Joint(world->GetJointList());
}
///<summary> You can use these to iterate over all the bodies, joints, and contacts. </summary>
/*
Contact^ GetContactList()
{
return gcnew Contact(world->C>GetContactList());
}
*/
/// <summary>
/// Query the world for all shapes that potentially overlap the
/// provided AABB. You provide a shape pointer buffer of specified
/// size. The number of shapes found is returned.
/// </summary>
IList<Shape^>^ Query(AABB^ aabb)
{
const int32 k_maxCount = 25;
b2Shape* shapes[k_maxCount];
int32 count = world->Query(aabb->getAABB(), shapes, k_maxCount);
List<Shape^>^ list = gcnew List<Shape^>();
for(int x = 0; x < count; ++x)
list->Add(gcnew Shape(shapes[x]));
return list;
}
static property bool PositionCorrection
{
bool get()
{
return b2World::s_enablePositionCorrection == 1;
}
void set(bool value)
{
b2World::s_enablePositionCorrection = value ? 1 : 0;
}
}
static property bool WarmStarting
{
bool get()
{
return b2World::s_enableWarmStarting == 1;
}
void set(bool value)
{
b2World::s_enableWarmStarting = value ? 1 : 0;
}
}
};
}
}
/*
class b2World
{
public:
// Register a world listener to receive important events that can
// help prevent your code from crashing.
void SetListener(b2WorldListener* listener);
// Register a collision filter to provide specific control over collision.
// Otherwise the default filter is used (b2CollisionFilter).
void SetFilter(b2CollisionFilter* filter);
*/
#pragma once
#include "stdafx.h"
#include "Vector.cpp"
#include "Matrix.cpp"
namespace Box2D
{
namespace Net
{
public ref class XForm
{
internal:
b2XForm *xform;
bool DeleteOnDtor;
XForm(b2XForm *XForm) : xform(XForm), DeleteOnDtor(false) { }
XForm(b2XForm XForm) : xform(new b2XForm(XForm)), DeleteOnDtor(false) { }
b2XForm getXForm()
{
return *xform;
}
public:
XForm() : xform(new b2XForm()), DeleteOnDtor(true) { }
~XForm()
{
if(DeleteOnDtor)
delete xform;
}
property Vector^ Position
{
Vector^ get()
{
return gcnew Vector(xform->position);
}
}
property Matrix^ Rotation
{
Matrix^ get()
{
return gcnew Matrix(xform->R);
}
}
};
}
}
namespace TestBed.Net
{
partial class MainWindow
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.panel1 = new System.Windows.Forms.Panel();
this.OpenGLControl = new Tao.Platform.Windows.SimpleOpenGlControl();
this.panel2 = new System.Windows.Forms.Panel();
this.label3 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.numericUpDown2 = new System.Windows.Forms.NumericUpDown();
this.numericUpDown1 = new System.Windows.Forms.NumericUpDown();
this.checkBox2 = new System.Windows.Forms.CheckBox();
this.checkBox1 = new System.Windows.Forms.CheckBox();
this.TestsComboBox = new System.Windows.Forms.ComboBox();
this.label1 = new System.Windows.Forms.Label();
this.RedrawTimer = new System.Windows.Forms.Timer(this.components);
this.panel1.SuspendLayout();
this.panel2.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).BeginInit();
this.SuspendLayout();
//
// panel1
//
this.panel1.Controls.Add(this.OpenGLControl);
this.panel1.Location = new System.Drawing.Point(12, 12);
this.panel1.Name = "panel1";
this.panel1.Size = new System.Drawing.Size(372, 242);
this.panel1.TabIndex = 3;
//
// OpenGLControl
//
this.OpenGLControl.AccumBits = ((byte)(0));
this.OpenGLControl.AutoCheckErrors = true;
this.OpenGLControl.AutoFinish = true;
this.OpenGLControl.AutoMakeCurrent = true;
this.OpenGLControl.AutoSwapBuffers = true;
this.OpenGLControl.BackColor = System.Drawing.Color.Black;
this.OpenGLControl.ColorBits = ((byte)(32));
this.OpenGLControl.DepthBits = ((byte)(16));
this.OpenGLControl.Location = new System.Drawing.Point(106, 62);
this.OpenGLControl.Name = "OpenGLControl";
this.OpenGLControl.Size = new System.Drawing.Size(137, 103);
this.OpenGLControl.StencilBits = ((byte)(0));
this.OpenGLControl.TabIndex = 1;
this.OpenGLControl.PreviewKeyDown += new System.Windows.Forms.PreviewKeyDownEventHandler(this.OpenGLControl_PreviewKeyDown);
this.OpenGLControl.MouseDown += new System.Windows.Forms.MouseEventHandler(this.OpenGLControl_MouseDown);
this.OpenGLControl.MouseMove += new System.Windows.Forms.MouseEventHandler(this.OpenGLControl_MouseMove);
this.OpenGLControl.MouseUp += new System.Windows.Forms.MouseEventHandler(this.OpenGLControl_MouseUp);
//
// panel2
//
this.panel2.Controls.Add(this.label3);
this.panel2.Controls.Add(this.label2);
this.panel2.Controls.Add(this.numericUpDown2);
this.panel2.Controls.Add(this.numericUpDown1);
this.panel2.Controls.Add(this.checkBox2);
this.panel2.Controls.Add(this.checkBox1);
this.panel2.Controls.Add(this.TestsComboBox);
this.panel2.Controls.Add(this.label1);
this.panel2.Location = new System.Drawing.Point(390, 12);
this.panel2.Name = "panel2";
this.panel2.Size = new System.Drawing.Size(170, 242);
this.panel2.TabIndex = 4;
//
// label3
//
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(18, 81);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(32, 13);
this.label3.TabIndex = 10;
this.label3.Text = "Hertz";
//
// label2
//
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(18, 55);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(50, 13);
this.label2.TabIndex = 9;
this.label2.Text = "Iterations";
//
// numericUpDown2
//
this.numericUpDown2.Location = new System.Drawing.Point(71, 79);
this.numericUpDown2.Name = "numericUpDown2";
this.numericUpDown2.Size = new System.Drawing.Size(71, 20);
this.numericUpDown2.TabIndex = 8;
this.numericUpDown2.Value = new decimal(new int[] {
60,
0,
0,
0});
//
// numericUpDown1
//
this.numericUpDown1.Location = new System.Drawing.Point(71, 53);
this.numericUpDown1.Name = "numericUpDown1";
this.numericUpDown1.Size = new System.Drawing.Size(71, 20);
this.numericUpDown1.TabIndex = 7;
this.numericUpDown1.Value = new decimal(new int[] {
60,
0,
0,
0});
//
// checkBox2
//
this.checkBox2.AutoSize = true;
this.checkBox2.Checked = true;
this.checkBox2.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox2.Location = new System.Drawing.Point(21, 128);
this.checkBox2.Name = "checkBox2";
this.checkBox2.Size = new System.Drawing.Size(93, 17);
this.checkBox2.TabIndex = 6;
this.checkBox2.Text = "Warm Starting";
this.checkBox2.UseVisualStyleBackColor = true;
//
// checkBox1
//
this.checkBox1.AutoSize = true;
this.checkBox1.Checked = true;
this.checkBox1.CheckState = System.Windows.Forms.CheckState.Checked;
this.checkBox1.Location = new System.Drawing.Point(21, 105);
this.checkBox1.Name = "checkBox1";
this.checkBox1.Size = new System.Drawing.Size(114, 17);
this.checkBox1.TabIndex = 5;
this.checkBox1.Text = "Position Correction";
this.checkBox1.UseVisualStyleBackColor = true;
//
// TestsComboBox
//
this.TestsComboBox.FormattingEnabled = true;
this.TestsComboBox.Location = new System.Drawing.Point(21, 26);
this.TestsComboBox.Name = "TestsComboBox";
this.TestsComboBox.Size = new System.Drawing.Size(121, 21);
this.TestsComboBox.TabIndex = 3;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(67, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(33, 13);
this.label1.TabIndex = 4;
this.label1.Text = "Tests";
//
// RedrawTimer
//
this.RedrawTimer.Enabled = true;
this.RedrawTimer.Interval = 30;
this.RedrawTimer.Tag = "";
this.RedrawTimer.Tick += new System.EventHandler(this.RedrawTimer_Tick);
//
// MainWindow
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(572, 457);
this.Controls.Add(this.panel2);
this.Controls.Add(this.panel1);
this.Name = "MainWindow";
this.Text = "MainWindow";
this.Resize += new System.EventHandler(this.MainWindow_Resize);
this.Load += new System.EventHandler(this.MainWindow_Load);
this.panel1.ResumeLayout(false);
this.panel2.ResumeLayout(false);
this.panel2.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown2)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.numericUpDown1)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Panel panel1;
private Tao.Platform.Windows.SimpleOpenGlControl OpenGLControl;
private System.Windows.Forms.Panel panel2;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.ComboBox TestsComboBox;
private System.Windows.Forms.Timer RedrawTimer;
private System.Windows.Forms.CheckBox checkBox2;
private System.Windows.Forms.CheckBox checkBox1;
private System.Windows.Forms.NumericUpDown numericUpDown2;
private System.Windows.Forms.NumericUpDown numericUpDown1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.Label label2;
}
}
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Tao.OpenGl;
using Box2D.Net;
using System.Reflection;
namespace TestBed.Net
{
public partial class MainWindow : Form
{
private Settings Settings = new Settings();
private Test mCurrentTest;
public Test CurrentTest
{
get
{
return mCurrentTest;
}
set
{
//Call code to reset current test
mCurrentTest = value;
}
}
public MainWindow()
{
InitializeComponent();
//Find all Tests in this module
foreach (Type type in Assembly.GetExecutingAssembly().GetExportedTypes())
{
Test test = new Test();
if (type.IsSubclassOf(test.GetType()))
{
TestsComboBox.Items.Add(System.Activator.CreateInstance(type));
}
}
TestsComboBox.SelectedIndex = 0;
CurrentTest = (Test)System.Activator.CreateInstance(TestsComboBox.SelectedItem.GetType());
OpenGLControl.Dock = DockStyle.Fill;
}
private void MainWindow_Load(object sender, EventArgs e)
{
OpenGLControl.InitializeContexts();
panel1.Dock = DockStyle.Fill;
panel2.Dock = DockStyle.Right;
MainWindow_Resize(null, null);
RedrawTimer.Interval = (int)(1000.0f / (float)Settings.Hz);
RedrawTimer.Start();
}
private void MainWindow_Resize(object sender, EventArgs e)
{
Size size = new Size(OpenGLControl.Size.Width - panel2.Width, OpenGLControl.Size.Height);
Renderer.InitOpenGL(size, CurrentTest.Zoom, CurrentTest.ViewOffset);
Renderer.OpenGLDraw(CurrentTest);
}
private void OpenGLControl_Paint(object sender, PaintEventArgs e)
{
Renderer.OpenGLDraw(CurrentTest);
}
private Vector RelativeCoordinates(Point MousePoint)
{
float Height = (float)OpenGLControl.Size.Height;
float Width = (float)(OpenGLControl.Size.Width - panel2.Width);
if(Height <= 0)
Height = 1;
float AspectRatio = Width / Height;
Vector relative = new Vector(
(float)MousePoint.X / Width,
(float)MousePoint.Y / Height);
relative -= new Vector(.5f, .5f);
relative *= 2;
relative.Y *= -1;
relative.X *= AspectRatio;
return relative;
}
private void OpenGLControl_MouseMove(object sender, MouseEventArgs e)
{
CurrentTest.MouseMove(RelativeCoordinates(e.Location));
}
private void OpenGLControl_MouseUp(object sender, MouseEventArgs e)
{
CurrentTest.MouseUp(RelativeCoordinates(e.Location));
}
private void OpenGLControl_MouseDown(object sender, MouseEventArgs e)
{
CurrentTest.MouseDown(RelativeCoordinates(e.Location));
}
private void RedrawTimer_Tick(object sender, EventArgs e)
{
CurrentTest.Step(Settings);
Renderer.OpenGLDraw(CurrentTest);
OpenGLControl.Draw();
int errorCode = 0;
if ((errorCode = Gl.glGetError()) > 0)
{
RedrawTimer.Stop();
//Handled by the OpenGLControl
//MessageBox.Show(Glu.gluErrorString(errorCode));
}
}
private void OpenGLControl_PreviewKeyDown(object sender, PreviewKeyDownEventArgs e)
{
if(e.KeyCode == Keys.R)
CurrentTest = (Test)System.Activator.CreateInstance(CurrentTest.GetType());
else
CurrentTest.KeyPress(e.KeyCode);
}
}
}
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<metadata name="RedrawTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root>
using System;
using System.Collections.Generic;
using System.Text;
using Box2D.Net;
using System.Windows.Forms;
namespace TestBed.Net
{
class Program
{
static void Main(string[] args)
{
Console.Title = "Box2D.Net Test Bed";
Application.EnableVisualStyles();
MainWindow win = new MainWindow();
Console.Write("Loading the OpenGL display window. Please be patient... ");
//Show above the console
win.Show();
win.BringToFront(); //Doesn't bring above the console?
win.TopMost = true; //Hacky fix instead:
win.TopMost = false;
Console.WriteLine("DONE");
Application.Run(win);
}
}
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("TestBed.Net")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TestBed.Net")]
[assembly: AssemblyCopyright("Copyright © 2008")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("c08bf3be-733a-49ed-820b-ad4f13ff3a00")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System;
using System.Collections.Generic;
using System.Text;
using Tao.OpenGl;
using Box2D.Net;
using System.Windows.Forms;
namespace TestBed.Net
{
static class Renderer
{
public static void InitOpenGL(System.Drawing.Size WidthHeight, float viewZoom, Vector ViewOffset)
{
int Width = WidthHeight.Width;
int Height = WidthHeight.Height;
Height = Height > 0 ? Height : 1;
Gl.glDisable(Gl.GL_CULL_FACE);
Gl.glClearColor(.5f, .5f, .5f, 1);
float AspectRatio = (float)Width / (float)Height;
Gl.glViewport(0, 0, Width, Height);
Gl.glMatrixMode(Gl.GL_PROJECTION);
Gl.glLoadIdentity();
Glu.gluOrtho2D(-AspectRatio, AspectRatio, -1, 1);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
}
public static void OpenGLDraw(Test test)
{
Gl.glClear(Gl.GL_COLOR_BUFFER_BIT);
Gl.glMatrixMode(Gl.GL_MODELVIEW);
Gl.glLoadIdentity();
Gl.glScalef(1.0f / test.Zoom, 1.0f / test.Zoom, 1.0f / test.Zoom);
Gl.glTranslatef(-test.ViewOffset.X, -test.ViewOffset.Y, 0);
Gl.glPushMatrix();
DrawBodies(test.world.Bodies);
DrawJoints(test.world.Joints);
Gl.glPopMatrix();
}
public static void DrawJoints(IList<Joint> joints)
{
foreach (Joint joint in joints)
{
DrawJoint(joint, System.Drawing.Color.LawnGreen);
}
}
public static void DrawBodies(IList<Body> bodies)
{
foreach(Body body in bodies)
foreach (Shape shape in body.Shapes)
{
System.Drawing.Color color = System.Drawing.Color.White;
if (body.Static)
color = System.Drawing.Color.LightGreen; //Color(0.5f, 0.9f, 0.5f)
else if (body.Sleeping)
color = System.Drawing.Color.LightBlue;
//else if(body == bomb)
DrawShape(body.GetXForm(), shape, System.Drawing.Color.White);
}
}
public static void DrawShape(XForm xform, Shape shape, System.Drawing.Color c)
{
switch (shape.ShapeType)
{
case ShapeType.e_circleShape:
{
Vector x = xform.Position;
float r = (new CircleShape(shape)).Radius;
float segments = 16;
double increment = 2 * Math.PI / segments;
Gl.glColor3ub(c.R, c.G, c.B);
Gl.glBegin(Gl.GL_LINE_LOOP);
for (double i = 0, theta = 0; i < segments; ++i, theta += increment)
{
Vector d = new Vector(r * (float)Math.Cos(theta), r * (float)Math.Sin(theta));
Vector v = x + d;
Gl.glVertex2f(v.X, v.Y);
}
Gl.glEnd();
//Draw a line from the circle's center to it's right side
//so we can visually inspect rotations.
Gl.glBegin(Gl.GL_LINES);
Gl.glVertex2f(x.X, x.Y);
Vector ax = xform.Rotation.col1;
Gl.glVertex2f(x.X + r * ax.X, x.Y + r * ax.Y);
Gl.glEnd();
}
break;
case ShapeType.e_polygonShape:
{
Gl.glColor3ub(c.R, c.G, c.B);
Gl.glBegin(Gl.GL_LINE_LOOP);
foreach (Vector vertex in (new PolyShape(shape)).Vertices)
{
Vector vertprime = xform.Rotation * vertex + xform.Position;
Gl.glVertex2f(vertprime.X, vertprime.Y);
}
Gl.glEnd();
}
break;
}
}
public static void DrawAABB(AABB aabb, System.Drawing.Color c)
{
Gl.glColor3b(c.R, c.G, c.B);
Gl.glBegin(Gl.GL_LINE_LOOP);
Gl.glVertex2f(aabb.lowerBound.X, aabb.lowerBound.Y);
Gl.glVertex2f(aabb.upperBound.X, aabb.lowerBound.Y);
Gl.glVertex2f(aabb.upperBound.X, aabb.upperBound.Y);
Gl.glVertex2f(aabb.lowerBound.X, aabb.upperBound.Y);
Gl.glEnd();
}
public static void DrawJoint(Joint joint, System.Drawing.Color color)
{
Body b1 = joint.Body1;
Body b2 = joint.Body2;
Vector x1 = b1.GetXForm().Position;
Vector x2 = b2.GetXForm().Position;
Vector p1 = joint.Anchor2;
Vector p2 = joint.Anchor1;
Gl.glColor3ub(color.R, color.G, color.B);
Gl.glBegin(Gl.GL_LINES);
switch (joint.JointType)
{
case JointType.e_mouseJoint:
case JointType.e_distanceJoint:
Gl.glVertex2f(p1.X, p1.Y);
Gl.glVertex2f(p2.X, p2.Y);
break;
/*
* case JointType.e_pulleyJoint:
{
b2PulleyJoint* pulley = (b2PulleyJoint*)joint;
b2Vec2 s1 = pulley->GetGroundPoint1();
b2Vec2 s2 = pulley->GetGroundPoint2();
glVertex2f(s1.x, s1.y);
glVertex2f(p1.x, p1.y);
glVertex2f(s2.x, s2.y);
glVertex2f(p2.x, p2.y);
}
break;
*/
default:
Gl.glVertex2f(x1.X, x1.Y);
Gl.glVertex2f(p1.X, p1.Y);
Gl.glVertex2f(x2.X, x2.Y);
Gl.glVertex2f(p2.X, p2.Y);
break;
}
Gl.glEnd();
}
}
}
using System;
using System.Collections.Generic;
using System.Text;
namespace TestBed.Net
{
public class Settings
{
public float Hz = 60;
public int IterationCount = 10;
public bool DrawStats = false;
public bool DrawContacts = false;
public bool DrawImpulses = false;
public bool DrawAABBs = false;
public bool DrawPairs = false;
public bool WarmStarting = true;
public bool PositionCorrection = true;
public bool Pause = false;
}
}
using System;
using System.Collections.Generic;
using System.Text;
using Box2D.Net;
using Tao.OpenGl;
namespace TestBed.Net
{
public class Test
{
public World world;
public MouseJoint mouseJoint;
public Body bomb;
public float Zoom = 20;
public Vector ViewOffset = new Vector();
public Vector Mouse = null;
public Test()
{
AABB worldAABB = new AABB(new Vector(-100.0f, -100.0f), new Vector(100.0f, 200.0f));
Vector gravity = new Vector(0, -10);
bool doSleep = true;
world = new World(worldAABB, gravity, doSleep);
//m_textLine = 30;
//
//m_listener.test = this;
//m_world->SetListener(&m_listener);
}
public void Step(Settings settings)
{
if(settings.Pause)
return;
float timeStep = settings.Hz > 0 ? 1.0f / settings.Hz : 0;
World.WarmStarting = settings.WarmStarting;
World.PositionCorrection = settings.PositionCorrection;
world.Step(timeStep, settings.IterationCount);
//m_world->m_broadPhase->Validate();
}
Vector RelativeToWorld(Vector Relative)
{
Vector working = Relative;
working *= Zoom;
working -= ViewOffset;
return working;
}
/// <summary>
/// Handles what happens when a user clicks the mouse
/// </summary>
/// <param name="p">
/// The position of the mouse click in relative coordinates.
/// </param>
public void MouseDown(Vector point)
{
Vector p = RelativeToWorld(point);
if (mouseJoint != null)
throw new Exception("ASSERT: mouseJoint should be null");
// Make a small box.
Vector d = new Vector(.001f, .001f);
AABB aabb = new AABB(p - d, p + d);
// Query the world for overlapping shapes.
IList<Shape> shapes = world.Query(aabb);
Body body = null;
foreach (Shape shape in shapes)
{
if (shape.Body.Static == false &&
shape.TestPoint(shape.Body.GetXForm(), p))
{
body = shape.Body;
break;
}
}
if (body != null)
{
MouseJointDef md = new MouseJointDef();
md.Body1 = world.GetGroundBody();
md.Body2 = body;
md.Target = p;
md.MaxForce = 1000 * body.Mass;
mouseJoint = new MouseJoint(world.CreateJoint(md));
body.WakeUp();
}
}
public void MouseUp(Vector point)
{
Vector p = RelativeToWorld(point);
if (mouseJoint != null)
{
world.DestroyJoint(mouseJoint);
mouseJoint = null;
}
}
public void MouseMove(Vector point)
{
Vector p = RelativeToWorld(point);
if (mouseJoint != null)
mouseJoint.SetTarget(p);
}
public void KeyPress(System.Windows.Forms.Keys key)
{
switch (key)
{
case System.Windows.Forms.Keys.Space:
LaunchBomb();
break;
case System.Windows.Forms.Keys.Left:
ViewOffset.X -= 1;
break;
case System.Windows.Forms.Keys.Right:
ViewOffset.X += 1;
break;
case System.Windows.Forms.Keys.Up:
ViewOffset.Y += 1;
break;
case System.Windows.Forms.Keys.Down:
ViewOffset.Y -= 1;
break;
case System.Windows.Forms.Keys.X:
Zoom -= 1;
break;
case System.Windows.Forms.Keys.Z:
Zoom += 1;
break;
}
}
void LaunchBomb()
{
if (bomb != null)
{
world.DestroyBody(bomb);
bomb = null;
}
BodyDef bd = new BodyDef();
bd.BodyType = BodyType.e_dynamicBody;
bd.AllowSleep = true;
Random rand = new Random();
bd.Position = new Vector((float)rand.NextDouble() * 30 - 15, 30.0f);
bd.IsBullet = true;
bomb = world.CreateBody(bd);
bomb.LinearVelocity = bd.Position * -5;
CircleDef sd = new CircleDef();
sd.Radius = 0.3f;
sd.Density = 20.0f;
sd.Restitution = 0.1f;
bomb.CreateShape(sd);
bomb.SetMassFromShapes();
}
public override string ToString()
{
return GetType().Name;
}
};
}
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>8.0.50727</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{B2F62680-048C-46AA-B1B2-7731252E1304}</ProjectGuid>
<OutputType>Exe</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>TestBed.Net</RootNamespace>
<AssemblyName>TestBed.Net</AssemblyName>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.Windows.Forms" />
<Reference Include="System.Xml" />
<Reference Include="Tao.FreeGlut, Version=2.4.0.1, Culture=neutral, PublicKeyToken=6e602a6ad6c0d06d, processorArchitecture=MSIL" />
<Reference Include="Tao.OpenGl, Version=2.1.0.4, Culture=neutral, PublicKeyToken=1ca010269a4501ef, processorArchitecture=MSIL" />
<Reference Include="Tao.Platform.Windows, Version=1.0.0.4, Culture=neutral, PublicKeyToken=701104b2da67a104, processorArchitecture=MSIL" />
</ItemGroup>
<ItemGroup>
<Compile Include="MainWindow.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="MainWindow.Designer.cs">
<DependentUpon>MainWindow.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Renderer.cs" />
<Compile Include="Settings.cs" />
<Compile Include="Test.cs" />
<Compile Include="Tests\Bridge.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Box2D.Net.vcproj">
<Project>{0E95DBB9-EA97-407B-811C-810B225E79D2}</Project>
<Name>Box2D.Net</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="MainWindow.resx">
<SubType>Designer</SubType>
<DependentUpon>MainWindow.cs</DependentUpon>
</EmbeddedResource>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
using System;
using System.Collections.Generic;
using System.Text;
using Box2D.Net;
namespace TestBed.Net.Tests
{
public class Bridge : TestBed.Net.Test
{
public Bridge()
{
Body ground;
{
PolygonDef sd = new PolygonDef();
sd.ShapeType = ShapeType.e_polygonShape;
sd.SetAsBox(50.0f, 10.0f);
BodyDef bd = new BodyDef();
bd.Position = new Vector(0, -10);
ground = world.CreateBody(bd);
ground.CreateShape(sd);
}
{
PolygonDef sd = new PolygonDef();
sd.SetAsBox(0.5f, 0.125f);
sd.Density = 20.0f;
sd.Friction = 0.2f;
BodyDef bd = new BodyDef();
bd.BodyType = BodyType.e_dynamicBody;
RevoluteJointDef jd = new RevoluteJointDef();
const float numPlanks = 30;
Body prevBody = ground;
for (float i = 0; i < numPlanks; ++i)
{
bd.Position = new Vector(-14.5f + i, 5);
Body body = world.CreateBody(bd);
body.CreateShape(sd);
body.SetMassFromShapes();
Vector anchor = new Vector(-15 + i, 5);
jd.Initialize(prevBody, body, anchor);
world.CreateJoint(jd);
prevBody = body;
}
Vector anchor2 = new Vector(-15 + numPlanks, 5);
jd.Initialize(prevBody, ground, anchor2);
world.CreateJoint(jd);
}
}
}
}
// <autogenerated />
using System;
using System.Reflection;
[assembly: global::System.Runtime.Versioning.TargetFrameworkAttribute(".NETFramework,Version=v4.0", FrameworkDisplayName = ".NET Framework 4")]
File deleted
cmake_minimum_required(VERSION 2.6)
set(BOX2D_VERSION 2.1.0)
set(BOX2D_BUILD_STATIC true)
set(BOX2D_DIR ../../../Box2D)
subdirs(${BOX2D_DIR}/Box2D)
project(iPhoneTestbed)
include_directories(${BOX2D_DIR} ${BOX2D_DIR}/Testbed/Tests)
file(GLOB iPhoneTestbed_Classes_SRCS Classes/*.mm)
source_group(Classes FILES ${iPhoneTestbed_Classes_SRCS})
set(CMAKE_OSX_SYSROOT iphoneos)
set(CMAKE_OSX_DEPLOYMENT_TARGET "")
set(CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT))
set(CMAKE_EXE_LINKER_FLAGS "-framework Foundation -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework UIKit")
set(MACOSX_BUNDLE_PRODUCT_NAME \${PRODUCT_NAME})
set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mycompany.\${PRODUCT_NAME:identifier}")
add_executable(iPhoneTestbed MACOSX_BUNDLE
${iPhoneTestbed_Classes_SRCS}
main.m
)
target_link_libraries(iPhoneTestbed Box2D)
set_target_properties(iPhoneTestbed PROPERTIES MACOSX_BUNDLE_INFO_PLIST Info.plist.in XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer")
set(APP_NAME \${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME})
find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin")
set(NIB MainWindow)
add_custom_command(TARGET iPhoneTestbed POST_BUILD
COMMAND /Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks Resources/* ${APP_NAME}
COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text --compile ${iPhoneTestbed_BINARY_DIR}/\${CONFIGURATION}/${PROJECT_NAME}.app/${NIB}.nib ${NIB}.xib
)
//
// Box2DAppDelegate.h
// Box2D
//
// Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com
//
#import <UIKit/UIKit.h>
#import "TestEntriesViewController.h"
#import "Delegates.h"
@class Box2DView;
@interface Box2DAppDelegate : NSObject <UIApplicationDelegate,TestSelectDelegate> {
UIWindow *window;
Box2DView *glView;
TestEntriesViewController *testEntriesView;
}
@property (nonatomic, retain) IBOutlet UIWindow *window;
@property (nonatomic, retain) IBOutlet Box2DView *glView;
@end
//
// Box2DAppDelegate.m
// Box2D
//
// Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com
//
#import <UIKit/UIKit.h>
#import "Box2DAppDelegate.h"
#import "Box2DView.h"
@implementation Box2DAppDelegate
@synthesize window;
@synthesize glView;
- (void)applicationDidFinishLaunching:(UIApplication *)application {
[application setStatusBarHidden:true];
[glView removeFromSuperview];
glView.animationInterval = 1.0 / 60.0;
testEntriesView=[[TestEntriesViewController alloc] initWithStyle:UITableViewStylePlain];
[testEntriesView setDelegate:self];
[glView setDelegate:self];
[window addSubview:[testEntriesView view]];
}
-(void) selectTest:(int) testIndex
{
[[testEntriesView view] removeFromSuperview];
[window addSubview:glView];
[glView startAnimation];
[glView selectTestEntry:testIndex];
}
-(void) leaveTest
{
[glView stopAnimation];
[glView removeFromSuperview];
[window addSubview:[testEntriesView view]];
}
- (void)applicationWillResignActive:(UIApplication *)application {
glView.animationInterval = 1.0 / 5.0;
}
- (void)applicationDidBecomeActive:(UIApplication *)application {
glView.animationInterval = 1.0 / 60.0;
}
- (void)dealloc {
[window release];
[glView release];
[super dealloc];
}
@end
//
// Box2DView.h
// Box2D OpenGL View
//
// Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com
//
#import <UIKit/UIKit.h>
#import <OpenGLES/EAGL.h>
#import <OpenGLES/ES1/gl.h>
#import <OpenGLES/ES1/glext.h>
#import "iPhoneTest.h"
#import "Delegates.h"
/*
This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
The view content is basically an EAGL surface you render your OpenGL scene into.
Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
*/
@interface Box2DView : UIView <UIAccelerometerDelegate> {
@private
/* The pixel dimensions of the backbuffer */
GLint backingWidth;
GLint backingHeight;
EAGLContext *context;
/* OpenGL names for the renderbuffer and framebuffers used to render to this view */
GLuint viewRenderbuffer, viewFramebuffer;
/* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */
GLuint depthRenderbuffer;
NSTimer *animationTimer;
NSTimeInterval animationInterval;
TestEntry* entry;
Test* test;
// Position offset and scale
float sceneScale;
CGPoint positionOffset;
CGPoint lastWorldTouch;
CGPoint lastScreenTouch;
bool panning;
int doubleClickValidCountdown;
id<TestSelectDelegate> _delegate;
}
@property(assign) id<TestSelectDelegate> delegate;
@property NSTimeInterval animationInterval;
- (void)startAnimation;
- (void)stopAnimation;
- (void)drawView;
-(void) selectTestEntry:(int) testIndex;
@end