Code Snippets

From Physics Simulation Wiki

Jump to: navigation, search

Contents

Code Snippets

Simple Triangle Meshes

I don't want anything complicated, I just want a simple triangle mesh that stuff can collide with! What's the simplest possible code to “just make a triangle mesh”?

Process 'highlight --fragment --syntax='cpp' --style-outfile='/tmp/highlight.css'' failed to start?

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

4gl, a4c, abp, ada, agda, ampl, amtrix, applescript, arc, arm, as, asm, asp, aspect, au3, avenue, awk, bat, bb, bib, bms, boo, c, cb, cfc, clipper, clp, cob, cs, css, d, diff, dot, dylan, e, erl, euphoria, exp, f77, f90, flx, frink, haskell, hcl, httpd, icn, idl, ini, inp, io, j, java, js, jsp, lbn, ldif, lgt, lisp, lotos, ls, lsl, lua, ly, m, make, mel, mib, miranda, ml, mo, mod3, mpl, ms, mssql, n, nas, nice, nsi, nut, oberon, objc, octave, oorexx, os, pas, php, pike, pl, pl1, pov, pro, progress, ps, ps1, psl, py, pyx, q, qu, r, rb, rexx, rnc, s, sas, sc, scala, scilab, sh, sma, smalltalk, sml, snobol, spec, spn, sql, sybase, tcl, tcsh, test_re, tex, ttcn3, txt, vb, verilog, vhd, xml, xpp, y

I want to constrain an object to two dimensional movement, skipping one of the cardinal axes

The best way of locking the motion in 2D is using btRigidBody::setLinearFactor and btRigidBody::setAngularFactor. This will be available in Bullet 2.75 (and in latest trunk).

btRigidBody::setLinearFactor takes a btVector3 as argument, where its x,y and z correspond to worldspace motion along those axis. Use a 1 to allow motion, and 0 to disallow motion along a certain axis.

The same for btRigidBody::setAngularFactor, where x,y and z corresponds to rotation along those axis.

If you want to limit the motion of objects in the X-Z plane, and only rotation along the Y axis, use:

Process 'highlight --fragment --syntax='cpp' --style-outfile='/tmp/highlight.css'' failed to start?

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

4gl, a4c, abp, ada, agda, ampl, amtrix, applescript, arc, arm, as, asm, asp, aspect, au3, avenue, awk, bat, bb, bib, bms, boo, c, cb, cfc, clipper, clp, cob, cs, css, d, diff, dot, dylan, e, erl, euphoria, exp, f77, f90, flx, frink, haskell, hcl, httpd, icn, idl, ini, inp, io, j, java, js, jsp, lbn, ldif, lgt, lisp, lotos, ls, lsl, lua, ly, m, make, mel, mib, miranda, ml, mo, mod3, mpl, ms, mssql, n, nas, nice, nsi, nut, oberon, objc, octave, oorexx, os, pas, php, pike, pl, pl1, pov, pro, progress, ps, ps1, psl, py, pyx, q, qu, r, rb, rexx, rnc, s, sas, sc, scala, scilab, sh, sma, smalltalk, sml, snobol, spec, spn, sql, sybase, tcl, tcsh, test_re, tex, ttcn3, txt, vb, verilog, vhd, xml, xpp, y

I want to cap the speed of my spaceship

What's important here is two things: Firstly, doing it in a manner that doesn't go against general physics coding karma. Secondly, doing it in a way that is framerate-independant.

source: darkrockstudios.com/files/bulletthings.pdfTłumaczenie strony 26 maj 2008 - 1.1 What do the parameters to btDynamicsWorld::stepSimulation mean? ... with them, then one way to help fix this problem is by decreasing fixedTimeStep. .... What's important here is two things: Firstly, doing it in a manner that doesn't go against general physics coding karma. Secondly, doing it in a way ...

To avoid messing with general physics coding karma, you should make sure you don't accidentally do this while the physics is actually stepping, and while you'd ideally like to avoid setting properties directly on the body, in this particular case you don't have a choice.

To make sure that this is done in a manner that leads to framerate-indepedance, you need to do it *every* time that bullet ticks internally. Just waiting for stepSimulation to return is insufficient since your spaceship might be above the max velocity for multiple internal ticks.

In short, the best way to do this is by setting the velocity of your spaceship in the physics tick molykote callback.

Process 'highlight --fragment --syntax='cpp' --style-outfile='/tmp/highlight.css'' failed to start?

You need to specify a language like this: <source lang="html">...</source>

Supported languages for syntax highlighting:

4gl, a4c, abp, ada, agda, ampl, amtrix, applescript, arc, arm, as, asm, asp, aspect, au3, avenue, awk, bat, bb, bib, bms, boo, c, cb, cfc, clipper, clp, cob, cs, css, d, diff, dot, dylan, e, erl, euphoria, exp, f77, f90, flx, frink, haskell, hcl, httpd, icn, idl, ini, inp, io, j, java, js, jsp, lbn, ldif, lgt, lisp, lotos, ls, lsl, lua, ly, m, make, mel, mib, miranda, ml, mo, mod3, mpl, ms, mssql, n, nas, nice, nsi, nut, oberon, objc, octave, oorexx, os, pas, php, pike, pl, pl1, pov, pro, progress, ps, ps1, psl, py, pyx, q, qu, r, rb, rexx, rnc, s, sas, sc, scala, scilab, sh, sma, smalltalk, sml, snobol, spec, spn, sql, sybase, tcl, tcsh, test_re, tex, ttcn3, txt, vb, verilog, vhd, xml, xpp, y

Personal tools