Search in sources :

Example 6 with SimpleSpatial

use of spacegraph.space3d.SimpleSpatial in project narchy by automenta.

the class ForceDirected method attract.

protected static void attract(Collidable x, Collidable y, float speed, float idealDist) {
    SimpleSpatial xp = ((SimpleSpatial) x.data());
    SimpleSpatial yp = ((SimpleSpatial) y.data());
    v3 delta = v();
    delta.sub(yp.transform(), xp.transform());
    float lenSq = delta.lengthSquared();
    if (!Float.isFinite(lenSq))
        return;
    if (lenSq < idealDist * idealDist)
        return;
    delta.normalize();
    // constant speed
    // delta.scale( speed );
    // speed proportional to length
    float len = (float) Math.sqrt(lenSq);
    delta.scale(Math.min(len, len * speed));
    ((Body3D) x).velAdd(delta);
    // delta2.scale(-(speed * (yp.mass() /* + yp.mass()*/) ) * len  );
    delta.scale(-1);
    ((Body3D) y).velAdd(delta);
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial) Body3D(spacegraph.space3d.phys.Body3D) spacegraph.util.math.v3(spacegraph.util.math.v3)

Example 7 with SimpleSpatial

use of spacegraph.space3d.SimpleSpatial in project narchy by automenta.

the class ExampleStereoTwoViewsOneCamera method main.

public static void main(String[] args) throws InterruptedException {
    ExampleStereoTwoViewsOneCamera e = new ExampleStereoTwoViewsOneCamera();
    new SpaceGraphPhys3D(new SimpleSpatial(e) {

        @Override
        public void renderAbsolute(GL2 gl, int dtMS) {
            for (ColorPoint3D p : e.gui.view.cloud) {
                int cc = p.rgb;
                gl.glColor3f(Bitmap2D.decodeRed(cc), Bitmap2D.decodeGreen(cc), Bitmap2D.decodeBlue(cc));
                Draw.rect(gl, (float) p.x, (float) p.y, 1, 1, (float) p.z);
            }
        }
    }).show(800, 800);
    RayTracer r = RayTracer.raytracer();
    r.update();
    r.renderProgressively();
    r.scene.camera.position.x = 4 - 1;
    // r.scene.camera.direction.x = -0.577 + 0.25f;
    r.update();
    r.renderProgressively();
    e.snap(r.image);
    Thread.sleep(200);
    // new Thread(()->{
    double t = 0;
    // while (true) {
    r.scene.camera.position.x = 4 + 1;
    // r.scene.camera.direction.x = -0.577 - 0.25f;
    r.update();
    if (r.renderProgressively()) {
        r.input.waitForInput();
    }
    // r.scene.camera.position.x += Math.cos(t)*0.2f;
    t += 0.2f;
    // }
    // }).start();
    // new Thread(()->{
    // while (true) {
    e.snap(r.image);
    try {
        Thread.sleep(250);
    } catch (InterruptedException e1) {
        e1.printStackTrace();
    }
// }
// 
// }).start();
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial) ColorPoint3D(boofcv.gui.d3.ColorPoint3D) GL2(com.jogamp.opengl.GL2) SpaceGraphPhys3D(spacegraph.space3d.SpaceGraphPhys3D) RayTracer(spacegraph.slam.raytrace.RayTracer) DetectDescribePoint(boofcv.abst.feature.detdesc.DetectDescribePoint)

Example 8 with SimpleSpatial

use of spacegraph.space3d.SimpleSpatial in project narchy by automenta.

the class RetinaPixel method addSingleResult.

@Override
public float addSingleResult(Collisions.LocalRayResult rayResult, boolean normalInWorldSpace) {
    Object target = rayResult.collidable.data();
    if (target != parent) {
        float dist = v3.dist(worldPosition, rayResult.hitNormal);
        // System.out.println(rayResult.collidable.data() + " " + dist);
        worldHit.set(rayResult.hitNormal);
        if (target instanceof SimpleSpatial) {
            SimpleSpatial ss = ((SimpleSpatial) target);
            r = ss.shapeColor[0];
            g = ss.shapeColor[1];
            b = ss.shapeColor[2];
            a = distanceToAlpha(dist);
        }
    }
    return 0;
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial)

Example 9 with SimpleSpatial

use of spacegraph.space3d.SimpleSpatial in project narchy by automenta.

the class RoverMaze1 method main.

public static void main(String[] args) {
    Rover r = new Rover(new NARS().get()) {

        @Override
        protected void create(Dynamics3D world) {
            SimpleSpatial torso;
            add(torso = new SimpleSpatial("torso") {

                @Override
                protected CollisionShape newShape() {
                    // return new CylinderShape(v(1f, 0.1f, 1f));
                    return new BoxShape(v(1.6f, 0.1f, 1f));
                }

                @Override
                public float mass() {
                    return 40f;
                }
            });
            SimpleSpatial neck;
            add(neck = new SimpleSpatial("neck") {

                @Override
                protected CollisionShape newShape() {
                    // return new TetrahedronShapeEx(v(0,10,0), v(10,0,0), v(10,10,0), v(0,0,10));
                    return new CylinderShape(v(0.25f, 0.75f, 0.25f));
                }

                @Override
                protected Body3D create(Dynamics3D world) {
                    torso.body.clearForces();
                    Body3D n = super.create(world);
                    HingeConstraint p = new HingeConstraint(torso.body, body, v(0, 0.2f, 0), v(0, -1f, 0), v(1, 0, 0), v(1, 0, 0));
                    p.setLimit(-1.0f, 1.0f);
                    add(p);
                    return n;
                }

                @Override
                public float mass() {
                    return 10f;
                }
            });
            neck.shapeColor[0] = 1f;
            neck.shapeColor[1] = 0.1f;
            neck.shapeColor[2] = 0.5f;
            neck.shapeColor[3] = 1f;
            RetinaGrid rg = new RetinaGrid("cam1", v(), v(0, 0, 1), v(0.1f, 0, 0), v(0, 0.1f, 0), 6, 6, 4f) {

                @Override
                protected Body3D create(Dynamics3D world) {
                    Body3D l = super.create(world);
                    // move(0,-1,0);
                    // body.clearForces();
                    l.clearForces();
                    HingeConstraint p = new HingeConstraint(neck.body, body, v(0, 0.6f, 0), v(0, -0.6f, 0), v(0, 1, 0), v(0, 1, 0));
                    p.setLimit(-0.75f, 0.75f);
                    // Point2PointConstraint p = new Point2PointConstraint(body, torso.body, v(2, 0, 0), v(-2, 0, 0));
                    // p.impulseClamp = 0.01f;
                    // //p.damping = 0.5f;
                    // p.tau = 0.01f;
                    add(p);
                    return l;
                }
            };
            add(rg);
        }
    };
// new SpaceGraph<>(
// new Maze("x", 20, 20),
// r
// );//.setGravity(v(0, 0, -5)).show(1000, 1000);
}
Also used : NARS(nars.NARS) CylinderShape(spacegraph.space3d.phys.shape.CylinderShape) SimpleSpatial(spacegraph.space3d.SimpleSpatial) Body3D(spacegraph.space3d.phys.Body3D) Dynamics3D(spacegraph.space3d.phys.Dynamics3D) BoxShape(spacegraph.space3d.phys.shape.BoxShape) HingeConstraint(spacegraph.space3d.phys.constraint.HingeConstraint)

Aggregations

SimpleSpatial (spacegraph.space3d.SimpleSpatial)9 Body3D (spacegraph.space3d.phys.Body3D)4 spacegraph.util.math.v3 (spacegraph.util.math.v3)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)1 ColorPoint3D (boofcv.gui.d3.ColorPoint3D)1 GL2 (com.jogamp.opengl.GL2)1 Quaternion (com.jogamp.opengl.math.Quaternion)1 NARS (nars.NARS)1 RayTracer (spacegraph.slam.raytrace.RayTracer)1 Surface (spacegraph.space2d.Surface)1 SpaceGraphPhys3D (spacegraph.space3d.SpaceGraphPhys3D)1 Spatial (spacegraph.space3d.Spatial)1 Collidable (spacegraph.space3d.phys.Collidable)1 Dynamics3D (spacegraph.space3d.phys.Dynamics3D)1 HingeConstraint (spacegraph.space3d.phys.constraint.HingeConstraint)1 Transform (spacegraph.space3d.phys.math.Transform)1 BoxShape (spacegraph.space3d.phys.shape.BoxShape)1 CylinderShape (spacegraph.space3d.phys.shape.CylinderShape)1 SimpleBoxShape (spacegraph.space3d.phys.shape.SimpleBoxShape)1 SpaceWidget (spacegraph.space3d.widget.SpaceWidget)1