Physics and Collision Detection Engines for Computer Applications

Physics and Collision Detection Engines for Computer Applications

Length: 1422 words (4.1 double-spaced pages)

Rating: Excellent

Open Document

Essay Preview

More ↓
Includes program code

Physics engines are used to simulate real physical interactions in a virtual environment. Many 3d based applications have physic engines included. Software such as modeling and animation programs, have physics engines that tell the program how the models react to certain forces to make them seem more realistic. This is used in the movie industry when creating computer generated effects to composite with live footage. They computer generated images need to look and react the same as real objects. Physics engines help determine the Game software include physics engines to create a a richer environment for the gamer to experience. By using physics engines, encounters do not have to follow pre-scripted courses, but can appear to react as they would in the real world. In both industries effects such as fire, smoke, fluid dynamics, and geometry-based sound all benefit from physics engines. Nothing moves by itself. Animating objects using traditional methods is complicated and time-consuming. You have to "tell" the object specifically where to go and what to do. Creating natural motion means that objects will respond to environmental forces spontaneously. For example, if there is nothing to support it, an object should fall to the ground and come to rest. Physics-based simulation is a first step in making objects move the way they do in real-life, but there is more to it than that. The aim of natural behavior technology is to generate the expected behavior of the objects that appear in a 3D application. This includes satisfying the laws of physics (or an interesting deviation from them) and some degree of artificial intelligence and autonomous simulated behavior.

Physics engines are basically code libraries. When a object is created it is giving a set of values for mass, height, weight, initial velocity, center of gravity, ect, ect. Then when a reaction needs to be calculated these values are used along with the correct formula. These formulas are part of the library and are stored along with it. The reason physics engines are hard to create is because it has to write functions to caculate certain reactions and has to have functions for every single reaction that could take place. In more complex environments there could be millions of formulas needed to be able to give correct answers for all the reactions. They used as reference libraries in the coding for the particular application that needs a physics engine and the functions are called on in that code.

How to Cite this Page

MLA Citation:
"Physics and Collision Detection Engines for Computer Applications." 123HelpMe.com. 17 Oct 2018
    <https://www.123helpme.com/view.asp?id=153554>.

Need Writing Help?

Get feedback on grammar, clarity, concision and logic instantly.

Check your paper »

Physics and Computer Games Essay

- Computer games have steadily become a form of mainstream entertainment ever since Pong was released back in 1958. Today, it is hard to find an electronics department in any store that doesn't carry some sort of computer game. "Big deal," you say, "Everyone knows about computer games. What does they have to do with physics?" Well, the technology for creating more powerful software is constantly advancing, and since games are a form of software, they too become more and more advanced. As games become more advanced, game developers aim to create games that offer a more realistic experience....   [tags: Physics Computers Science Video Games]

Free Essays
1005 words (2.9 pages)

Computer Security: Antivirus Softwares Essay

- Introduction Computers are becoming more and more important machine and the uses of computer are becoming variety in our life. The reason for using of computer on different purpose, people are looking for computer specifications which they need. To satisfy people’s needs, the computers are developing fast, however as the growth of use of computer, computer is not the only one developing the internet is developing rapidly. The internet is essential in our life now. Over billions of people around world use internet to communicate with each other or get information they need faster without any limitation of time and places....   [tags: Computer Virus Detection]

Research Papers
2425 words (6.9 pages)

Network Intrusion Detection and Prevention Essay

- There are a few different types of Intrusion Detection and Prevention systems and techniques out on the market today. I will go over some of the standards used to help secure businesses and data all over the world. First there is the term passive and active security, passive security is like a firewall and blocks attacks based on rules, settings, or an internet content filter that blocks malicious web sites. Intrusion Detection Systems (IDS) is a device that uses active security; this can detect an attack as it occurs....   [tags: Computer Networking]

Research Papers
1209 words (3.5 pages)

An Introduction To Intrusion Detection Systems Essay example

- I decided to write my paper on Intrusion Detection Systems (IDS) and Intrusion Prevention Systems (IPS) because professor mentioned these devices several times in class and I am interested in network security therefore it was a good opportunity for me to learn more about these security systems. An intrusion detection system (IDS) generally detects unwanted manipulations to computer systems, mainly through the Internet. The manipulations may take the form of attacks by crackers. An intrusion detection system is used to detect many types of malicious network traffic and computer usage that can't be detected by a conventional firewall....   [tags: Computer Network Security]

Free Essays
1185 words (3.4 pages)

Various Brain Tumor Detection Techniques Essay

- Brain tumor is an abnormal mass of tissue in which some cells grow or multiply uncontrollably. Various techniques have been developed for detection of brain tumor. This paper focuses on survey of well-known brain tumor detection techniques and the applied image segmentation procedures. The main concentration is on the techniques which use image segmentation to detect brain tumor. These techniques include Magnetic Resonance Imaging (MRI), functional MRI (fMRI), Computed Tomography ( CT ) Scans and various others....   [tags: Computed tomography, tumor, MRI]

Research Papers
3133 words (9 pages)

Essay on Corner Detection Are Useful for Computer Vision Applications

- ... The Kitchen and Rosenfeld operator [5] uses an analysis of the curvature of the grey-level variety of an image. The SUSAN operator [18] uses a form of grey-level moment that is designed to detect V- corners, and which is applied to other model of corner. The earlier Forstner [22] algorithm is easily explained in terms of H (Hessian Matrix). For a more recently proposed detector [20], it has been shown [21] that under affine motion, it is better to use the smallest eigenvalue of H as the corner strength function....   [tags: vertex, edges, parameters]

Research Papers
1486 words (4.2 pages)

Heterogeneous Parallel Ensemble Classifiers for Face Detection Essay

- Heterogeneous Parallel Ensemble Classifiers for Face Detection Abstract - Face detection is a process to determine the presence of a human face in a given image, and if exists then returns the location of detected face. Face detection is a difficult process due to certain factors, such as background complexity, illumination conditions, scale, expression, position, orientation and pose of the face. The presence of external facial features such as glasses, moustaches and beards further complicates the process of face detection....   [tags: Computer Science ]

Research Papers
1352 words (3.9 pages)

Jet Engines Essay

- The Basics A jet engine can be divided into several distinct sections: intake, compressor, diffuser, combustion chamber, turbine, and exhaust. These sections are much like the different cycles in a four-stroke reciprocating engine: intake, compression, power and exhaust. In a four-stroke engine a fuel/air mixture is is brought into the engine (intake), compressed (compression), and finally ignited and pushed out the exhaust (power and exhaust). In it's most basic form, a jet engine works in much the same way....   [tags: physics jet jets engine engines]

Free Essays
1984 words (5.7 pages)

Issues Raised by Use of Turnitin Plagiarism Detection Software Essay

- Issues Raised by Use of Turnitin Plagiarism Detection Software This past week, I worked with a couple of other members of the Writing Department at GVSU to prepare a position statement on plagiarism detection software. GVSU only recently acquired a subscription to Turnitin, and myself and the other teachers were concerned that teachers in other disciplines would be unware of the issues surrounding plagiarism detection services. The following is the full text of the statement which has been distributed on our campus....   [tags: Plagiarism Detection Software]

Free Essays
949 words (2.7 pages)

Essay about A Guide on Search Engines

- A Guide on Search Engines Hello and welcome. My name is Jane, and I'm reporting to you live from Hollywood. I am sporting a lovely plum-colored sequence dress compliments of Bergdorf, and the jewelry I am seen wearing are from Tiffany & Co. Well ladies and gentlemen, enough about my lovely attire. The moment we've all been waiting for has come. Finally, movie critics from around the United States have gathered to criticize or glorify the upcoming movie, Search Engines. With the success this movie is supposed to receive, sequels are already being talked about....   [tags: Technology Computers Internet Essays]

Free Essays
1717 words (4.9 pages)



The following is example code that would be used to determine collision in a complicated envirnment. In this case there is a large array of pendulums disrupted by a falling wood block.



This is a simulation for only one set of objects, you can imagine how complex this would get if you had an entire environment to provide reactions for.



/*
Copyright MathEngine PLC 2000
www.mathengine.com

$Name: AUTO_TEMP_MeTKMakeRelease_1_299 $

$Id: ManyPendulums.c,v 1.16 2000/08/31 13:52:45 lyndonh Exp $
*/

/*
This example shows the collision detection, Dynamics Event Manager
and Kea Dynamics working on a complicated environment.
*/

#pragma warning( disable : 4305 )

#include "MePrecision.h"
#include "McdFrame.h"
#include "McdPrimitives.h"
#include "McdDtBridge.h"
#include "Mdt.h"
#include "MeMath.h"

#include "MeViewer.h"

extern struct MeMemoryAPI MeMemoryAPIMalloc;
struct MeMemoryOptions opts;

/* Global declarations */

/* Number of pendulums down one side of grid */
#define NSIDE 20
#define NPENDULUMS (NSIDE * NSIDE)

#define penRadius (MeReal)0.5
#define penHeight (MeReal)2.0
#define penJoint (MeReal)5.0
#define penDensity (MeReal)8.0
#define penSpacing (MeReal)3.0

/* MeReal penRadius = (MeReal)0.5; */
/* MeReal penHeight = (MeReal)2.0; */
/* MeReal penJoint = (MeReal)5.0; */
/* MeReal penDensity = (MeReal)8.0; */
/* MeReal penSpacing = (MeReal)3.0; */

MeReal thingDensity = 1.0;
MeVector3 thingDim = {3.8, 3.8, 3.8};
MeVector3 thingStart = {0.8, 20.0, 0.01};

/* color of pendulums in the corners */
MeVector3 topLeftColor = {1, 0, 0};
MeVector3 topRightColor = {1, 1, 0};
MeVector3 bottomLeftColor = {0, 1, 0};
MeVector3 bottomRightColor = {0, 0, 1};

/* Force applied to the box to drag it around */
MeReal thingForce = 1000;

/* World for the Dynamics Toolkit simulation */
MdtWorldID world;

/* Collision */
McdDtBridge *cdHandler;
McdSpaceID space;

/* Kea solver workspace */
void *KeaMemoryArea;

/* Physics representations */
MdtBodyID thing;
MdtBodyID pen[NPENDULUMS];
MdtBSJointID joint[NPENDULUMS];

/* Graphical representations */
RGraphic *groundG;
RGraphic *thingG;
RGraphic *penG[NPENDULUMS];
RGraphic *lineG[NPENDULUMS];

/* Collision reps */
McdModelID groundCM;
McdModelID thingCM;
McdModelID penCM[NPENDULUMS];
McdGeometryID plane_prim, box_prim, pen_prim[NPENDULUMS];

MeReal gravity[3] = { 0, -10, 0 };

/* Render context */
RRender *rc;

/* Timestep size */
MeReal step = (MeReal)(0.04);

MeReal groundTransform[4][4] =
{
{1, 0, 0, 0},
{0, 0, -1, 0},
{0, 1, 0, 0},
{0, -1, 0, 1}
};

MeReal groundRenderTransform[16] =
{
1, 0, 0, 0,
0, 0, -1, 0,
0, 1, 0, 0,
0, -1.5, 0, 1
};

/* Functions to add forces to block to drag it around. */
void increaseXForce(void)
{
MdtBodyEnable(thing);
MdtBodyAddForce(thing, thingForce, 0, 0);
}


void decreaseXForce(void)
{
MdtBodyEnable(thing);
MdtBodyAddForce(thing, -thingForce, 0, 0);
}


void increaseZForce(void)
{
MdtBodyEnable(thing);
MdtBodyAddForce(thing, 0, 0, thingForce);
}


void decreaseZForce(void)
{
MdtBodyEnable(thing);
MdtBodyAddForce(thing, 0, 0, -thingForce);
}


void ThingCameraTrack()
{
MeVector3 pos;
MdtBodyGetPosition(thing, pos);
rc->m_cameraLookAt[0] = pos[0];
rc->m_cameraLookAt[1] = pos[1];
rc->m_cameraLookAt[2] = pos[2];
RUpdateCamera();
}


/*
Tick() is a callback function called from the renderer's main loop
to evolve the world by 'step' seconds
*/
void tick(RRender * rc)
{
/*
These timer calls are for the OpenGL performance bar.
*/
RStopTimer(kRRender);

/* Update collision */
RStartTimer(kRCollision);
McdDtBridgeUpdateAllFreezeFlags(space);
McdPairHandlerUpdate();
RStopTimer(kRCollision);

/* Update dynamics */
RStartTimer(kRDynamics);
MdtWorldStep(world, step);
RStopTimer(kRDynamics);

RStartTimer(kRRender);

ThingCameraTrack();
}


/*
Reset boxes and pendulums to initial positions
*/
void reset(void)
{
int i,j;

/* Offset to start making pendulums from */
MeReal start = (NSIDE-1) * -penSpacing * (MeReal)0.5;

MdtBodySetPosition(thing, thingStart[0], thingStart[1], thingStart[2]);
MdtBodySetQuaternion(thing, 1, 0, 0, 0);
MdtBodySetLinearVelocity(thing, 0, 0, 0);
MdtBodySetAngularVelocity(thing, 0, 0, 0);
MdtBodyEnable(thing);

for (i = 0; i < NSIDE; i++)
{
for(j=0; j < NSIDE; j++)
{
MdtBodySetPosition(pen[(i*NSIDE)+j], start + i * penSpacing, penHeight, start + j * penSpacing);
MdtBodySetQuaternion(pen[(i*NSIDE)+j], 1, 0, 0, 0);
MdtBodySetLinearVelocity(pen[(i*NSIDE)+j], 0, 0, 0);
MdtBodySetAngularVelocity(pen[(i*NSIDE)+j], 0, 0, 0);
MdtBodyEnable(pen[(i*NSIDE)+j]);
}
}
}

void cleanup(void)
{
int i;
McdGeometryDestroy(plane_prim);
McdModelDestroy(groundCM);

McdGeometryDestroy(box_prim);
McdModelDestroy(thingCM);

for (i = 0; i < NPENDULUMS; i++)
{
McdGeometryDestroy(pen_prim[i]);
McdModelDestroy(penCM[i]);
}

McdSpaceDestroy(space);
McdDtBridgeDestroy(cdHandler);
McdDtBridgeTerm();
McdTerm();

MdtWorldDestroy(world);
free(KeaMemoryArea);

RDeleteRenderContext(rc);
}

/*
Main Routine
*/

int main(int argc, const char **argv)
{
const RRenderType render = RParseRenderType(&argc, &argv);

#ifndef PS2
static char *help[] =
{
"Left Mouse Drag - move camera",
" Enter - reset",
" w,a,s,d - drag block around"
};
#else
static char *help[] =
{
" Start - reset",
" Directional pad - drag block around"
};
#endif
const int helpNum = sizeof (help) / sizeof (help[0]);

int i, j, k, id;
float color[3];
short material1;
MeReal mass, start;
MeMatrix3 I;
AcmeReal lineStart[3] = { 0.0, penRadius, 0.0};
AcmeReal lineEnd[3] = { 0.0, penJoint - penHeight, 0.0};

MeVector3 tempColorTop, tempColorBottom;
MeReal propI, propJ;
MdtContactParamsID props;

if (render == kRD3D) {
MeInfo(0,"Direct3D not supported for this example.\n");
exit(1);
}

MeMemorySetDefaults(&opts);
(*MeMemoryAPI.setOptions)(&opts);

/*
Initialise dynamics
*/

KeaMemoryArea = malloc(2000000);

world = MdtWorldCreate(NPENDULUMS + 1, NPENDULUMS + 100, KeaMemoryArea, 2000000);

MdtWorldSetGravity(world, gravity[0], gravity[1], gravity[2]);

/*
In this demo, a lot of objects are stationary a lot of the time.
To speed things up we tell Mdt to AutoDisable objects when they
come to rest. Disabled MdtBodies are automatically re-Enabled
when an Enabled body contacts them.
*/
MdtWorldSetDEMMode(world, MdtDEMModePartitionAutoDisable);

/*
THING:
*/

thing = MdtBodyCreate(world);

mass = thingDensity * thingDim[0] * thingDim[1] * thingDim[2];

MdtMakeInertiaTensorBox(mass, thingDim[0], thingDim[1], thingDim[2], I);

MdtBodySetMass(thing, mass);
MdtBodySetInertiaTensor(thing, I);

/*
Add a little (angular)velocity damping
*/
MdtBodySetAngularVelocityDamping(thing, 0.03);
MdtBodySetLinearVelocityDamping(thing, 0.02);

/*
PENDULUMS:
*/

mass = PI * penRadius * penRadius * penDensity;
MdtMakeInertiaTensorSphere(mass, penRadius, I);

for (i = 0; i < NPENDULUMS; i++)
{
pen[i] = MdtBodyCreate(world);

MdtBodySetMass(pen[i], mass);
MdtBodySetInertiaTensor(pen[i], I);

MdtBodySetLinearVelocityDamping(pen[i], (MeReal)(0.2));
MdtBodySetAngularVelocityDamping(pen[i], (MeReal)(0.1));
}

/* reset pendulums to correct positions.. */
reset();

/* offset to start making pendulums from */
start = (NSIDE-1) * -penSpacing * (MeReal)0.5;

/* now make all the joints */
for (i = 0; i < NSIDE; i++)
{
for(j=0; j < NSIDE; j++)
{
joint[(i*NSIDE)+j] = MdtBSJointCreate(world, pen[(i*NSIDE)+j], 0);
MdtBSJointSetPosition(joint[(i*NSIDE)+j], start + i * penSpacing, penJoint, start + j * penSpacing);
MdtBSJointEnable(joint[(i*NSIDE)+j]);
}
}


/*
Collision detection
*/
McdInit(McdPrimitivesGetTypeCount());

McdPrimitivesRegisterTypes();
McdPrimitivesRegisterInteractions();

McdDtBridgeInit(0);

/* max objects and pairs */
space = McdSpaceAxisSortCreate(McdAllAxes, NPENDULUMS + 2, 150);
McdPairHandlerRegisterSpace(space);

cdHandler = McdDtBridgeCreate();

/* max pairs at a time */
McdDtBridgeSetPairListMaxCount(cdHandler, 150);

/*
Set parameters for contacts.
*/
material1 = McdDtBridgeGetDefaultMaterialID();
props = McdDtBridgeGetContactParams(material1, material1);

MdtContactParamsSetType(props, MdtContactTypeFriction2D);
MdtContactParamsSetFriction(props, 2.0);
MdtContactParamsSetRestitution(props, 0.3);

/*
Only use 3 contacts per pair.
*/
id = McdIntersectGetDefaultRequestID();
McdIntersectRequestSetContactMaxCount(id, id, 3);

plane_prim = McdPlaneCreate();
groundCM = McdModelCreate(plane_prim);
McdSpaceInsertModel(space, groundCM);
McdDtBridgeSetBody(cdHandler, groundCM, 0);

McdModelSetTransformPtr(groundCM, groundTransform);

McdModelFreezeInSpace(groundCM);

box_prim = McdBoxCreate(thingDim[0],
thingDim[1], thingDim[2]);
thingCM = McdModelCreate(box_prim);
McdDtBridgeSetBody(cdHandler, thingCM, thing);
McdSpaceInsertModel(space, thingCM);


for (i = 0; i < NPENDULUMS; i++)
{
pen_prim[i] = McdBoxCreate(2 * penRadius,
2 * penRadius, 2 * penRadius);
penCM[i] = McdModelCreate(pen_prim[i]);
McdDtBridgeSetBody(cdHandler, penCM[i], pen[i]);
McdSpaceInsertModel(space, penCM[i]);
}

McdSpaceBuild(space);

/*
Initialise rendering attributes
*/

rc = RNewRenderContext(render, kRQualitySmooth);

rc->m_cameraOffset = 30;

RUpdateCamera();

/*
GROUND:
*/

color[0] = 0.0f;
color[1] = 0.75f;
color[2] = 0.1f;

groundG =
RCreateCube(rc, 84.0f, 84.0f, 0.5f, color,
groundRenderTransform);
#ifndef PS2
RSetTexture(groundG, "checkerboard");
#endif
color[0] = 0.1;
color[1] = 0.1;
color[2] = 0.8;

thingG =
RCreateCube(rc, thingDim[0], thingDim[1], thingDim[2],
color, MdtBodyGetTransformPtr(thing));

#ifndef PS2
RSetTexture(thingG, "wood1");
#endif

/* make graphics (pretty colours) */
for (i = 0; i < NSIDE; i++)
{
for(j=0; j < NSIDE; j++)
{
propI = (MeReal)i/((MeReal)NSIDE-1);
propJ = (MeReal)j/((MeReal)NSIDE-1);

for(k=0; k<3; k++)
{
tempColorTop[k] =
(propI * (topRightColor[k] - topLeftColor[k])) + topLeftColor[k];
tempColorBottom[k] =
(propI * (bottomRightColor[k] - bottomLeftColor[k])) + bottomLeftColor[k];
color[k] =
(propJ * (tempColorTop[k] - tempColorBottom[k])) + tempColorBottom[k];
}

penG[(i*NSIDE)+j] =
RCreateCube(rc, 2*penRadius, 2*penRadius, 2*penRadius,
color, MdtBodyGetTransformPtr(pen[(i*NSIDE)+j]));
lineG[(i*NSIDE)+j] =
RCreateLine(rc, lineStart, lineEnd,
color, MdtBodyGetTransformPtr(pen[(i*NSIDE)+j]));
}
}

/*
KEYS:
*/

#ifndef PS2
RUseKey('w', increaseZForce);
RUseKey('s', decreaseZForce);
RUseKey('a', decreaseXForce);
RUseKey('d', increaseXForce);

RUseKey('\r', reset);
#else
RUsePadKey(PADLup, increaseZForce);
RUsePadKey(PADLdown, decreaseZForce);
RUsePadKey(PADLright, decreaseXForce);
RUsePadKey(PADLleft, increaseXForce);
RUsePadKey(PADstart, reset);
#endif

/* selects a fixed-width font */
RSetOGLFont(3);

RCreateUserHelp(help, helpNum);
rc->m_title = "ManyPendulums example";

/*
Cleanup after simulation.
*/
#ifndef PS2
atexit(cleanup);
#endif
/*
Run the Simulation.
*/

/*
RRun() executes the main loop.

Pseudocode: while no exit-request { Handle user input call Tick() to
evolve the simulation and update graphic transforms Draw graphics }
*/

RRun(rc, tick);

return 0;
}

Return to 123HelpMe.com