
org.ode4j.demo.DemoCylVsSphere Maven / Gradle / Ivy
/*************************************************************************
* *
* Open Dynamics Engine, Copyright (C) 2001,2002 Russell L. Smith. *
* All rights reserved. Email: [email protected] Web: www.q12.org *
* Open Dynamics Engine 4J, Copyright (C) 2009-2014 Tilmann Zaeschke *
* All rights reserved. Email: [email protected] Web: www.ode4j.org *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of EITHER: *
* (1) The GNU Lesser General Public License as published by the Free *
* Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. The text of the GNU Lesser *
* General Public License is included with this library in the *
* file LICENSE.TXT. *
* (2) The BSD-style license that is included with this library in *
* the file ODE-LICENSE-BSD.TXT and ODE4J-LICENSE-BSD.TXT. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
* LICENSE.TXT, ODE-LICENSE-BSD.TXT and ODE4J-LICENSE-BSD.TXT for more *
* details. *
* *
*************************************************************************/
package org.ode4j.demo;
import org.ode4j.drawstuff.DrawStuff.dsFunctions;
import org.ode4j.math.DMatrix3;
import org.ode4j.math.DQuaternion;
import org.ode4j.math.DVector3;
import org.ode4j.ode.DCylinder;
import org.ode4j.ode.DSphere;
import org.ode4j.ode.OdeHelper;
import org.ode4j.ode.DBody;
import org.ode4j.ode.DContact;
import org.ode4j.ode.DContactBuffer;
import org.ode4j.ode.DGeom;
import org.ode4j.ode.DJoint;
import org.ode4j.ode.DJointGroup;
import org.ode4j.ode.DMass;
import org.ode4j.ode.DSpace;
import org.ode4j.ode.DWorld;
import org.ode4j.ode.OdeMath;
import static org.ode4j.drawstuff.DrawStuff.*;
/**
* Test for cylinder vs sphere, by Bram Stolk.
*/
class DemoCylVsSphere extends dsFunctions {
// dynamics and collision objects (chassis, 3 wheels, environment)
private static DWorld world;
private static DSpace space;
private static DBody cylbody;
private static DCylinder cylgeom;
private static DBody sphbody;
private static DSphere sphgeom;
private static DJointGroup contactgroup;
private static boolean show_contacts = true;
//#define CYLRADIUS 0.6
//#define CYLLENGTH 2.0
//#define SPHERERADIUS 0.5
private static final float CYLRADIUS = 0.6f;
private static final float CYLLENGTH = 2.0f;
private static final float SPHERERADIUS = 0.5f;
private DGeom.DNearCallback nearCallback = new DGeom.DNearCallback() {
@Override
public void call(Object data, DGeom o1, DGeom o2) {
nearCallback(data, o1, o2);
}
};
// this is called by dSpaceCollide when two objects in space are
// potentially colliding.
private void nearCallback (Object data, DGeom o1, DGeom o2)
{
assert(o1!=null);
assert(o2!=null);
if ( o1 instanceof DSpace || o2 instanceof DSpace )
{
System.err.println("testing space " + o1 + " " + o2);
// colliding a space with something
OdeHelper.spaceCollide2(o1,o2,data,nearCallback);
// Note we do not want to test intersections within a space,
// only between spaces.
return;
}
final int N = 32;
DContactBuffer contacts = new DContactBuffer(N);
int n = OdeHelper.collide (o1,o2,N,contacts.getGeomBuffer());
if (n > 0)
{
for (int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy