Search in sources :

Example 1 with SimpleSpatial

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

the class Spiral method update.

protected void update(Spatial v) {
    // TODO abstract
    // int hash = v.hash;
    // int vol = v.key.volume();
    // float ni = n / (float) Math.E;
    // final float bn = 1f;
    // float p = v.pri;
    // float nodeSpeed = (this.nodeSpeed / (1f + v.pri));
    int o = order++;
    float angle = o * angleRate;
    float r = baseRad + o * angleRate * 1.6f;
    SimpleSpatial vv = (SimpleSpatial) v;
    vv.body.clearForces();
    vv.body.setLinearVelocity(0, 0, 0);
    vv.move((float) (Math.sin(angle) * r), (float) (Math.cos(angle) * r), 0, nodeSpeed);
// 1f/(1f+v.lag) * (baseRad/2f);
// v.budget.qua() * (baseRad + rad)
// v.tp[2] = act*10f;
// nodeSpeed);
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial)

Example 2 with SimpleSpatial

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

the class Flatten method accept.

@Override
public void accept(Spatial<X> ss) {
    if (ss instanceof SimpleSpatial) {
        SimpleSpatial s = (SimpleSpatial) ss;
        // v3 f = v();
        // locate(s, f);
        // s.move(f, rate);
        Body3D b = s.body;
        if (b == null)
            return;
        float tz = b.transform.z;
        if (Math.abs(tz) > zTolerance) {
            // b.velAdd(v( 0, 0,
            // -(tz > 0 ? (tz - zTolerance) : (tz + zTolerance)) * zSpeed));
            b.linearVelocity.z *= zSpeed;
            b.transform.z *= zSpeed;
        } else {
        // dont affect
        }
        s.rotate(up, rotateRate, new Quaternion());
    // dampening: keep upright and eliminate z-component of linear velocity
    // b.linearVelocity.scale(
    // 1f, 1f, 0.9f
    // );
    // b.angularVelocity.scale(1f-rotateRate);
    // b.angularVelocity.zero();
    }
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial) Quaternion(com.jogamp.opengl.math.Quaternion) Body3D(spacegraph.space3d.phys.Body3D)

Example 3 with SimpleSpatial

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

the class EdgeDirected method solve.

@Override
public void solve(Broadphase b, List<Collidable> objects, float timeStep) {
    float a = attraction.floatValue();
    for (int i = 0, objectsSize = objects.size(); i < objectsSize; i++) {
        Collidable c = objects.get(i);
        Spatial A = ((Spatial) c.data());
        // TODO abstract the Edges as a feature to optionally add to a TermWidget, not just for ConceptWidgets
        if (A instanceof SpaceWidget) {
            ((SpaceWidget<?>) A).edges().forEach(e -> {
                float attraction = e.attraction;
                if (attraction > 0) {
                    SimpleSpatial B = e.tgt();
                    if ((B.body != null)) {
                        attract(c, B.body, a * attraction, e.attractionDist);
                    }
                }
            });
        }
    }
    super.solve(b, objects, timeStep);
}
Also used : Collidable(spacegraph.space3d.phys.Collidable) SpaceWidget(spacegraph.space3d.widget.SpaceWidget) SimpleSpatial(spacegraph.space3d.SimpleSpatial) Spatial(spacegraph.space3d.Spatial) SimpleSpatial(spacegraph.space3d.SimpleSpatial)

Example 4 with SimpleSpatial

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

the class Cuboid method onTouch.

@Override
public Surface onTouch(Finger finger, Collidable body, ClosestRay r, short[] buttons, SpaceGraphPhys3D space) {
    if (body != null) {
        // rotate to match camera's orientation (billboarding)
        Object d = body.data();
        if (d instanceof SimpleSpatial) {
            SimpleSpatial sd = (SimpleSpatial) d;
        // Quat4f target = Quat4f.angle(-space.camFwd.x, -space.camFwd.y, -space.camFwd.z, 0);
        // Quat4f target = new Quat4f();
        // sd.rotate( -space.camFwd.x, -space.camFwd.y, -space.camFwd.z, 0, 0.2f);
        // com.jogamp.common.util.SyncedRingbuffer
        // Transform bt = body.worldTransform;
        // // TODO somehow use the object's local transformation ? sd.transform().getRotation(...);
        // target.setAngle(
        // space.camFwd.x-bt.x,
        // space.camFwd.y - bt.y,
        // space.camFwd.z -bt.z,
        // (float) Math.PI
        // );
        // 
        // target.normalize();
        // 
        // sd.rotate(target, 0.2f); //new Quat4f());
        // //System.out.println("  : " + sd.transform().getRotation(new Quat4f()));
        }
        // 
        Surface s0 = super.onTouch(finger, body, r, buttons, space);
        if (s0 != null)
            return s0;
    }
    if (front != null) {
        Transform it = Transform.t(transform).inverse();
        v3 localPoint = it.transform(v(r.hitPointWorld));
        if (body != null && body.shape() instanceof SimpleBoxShape) {
            SimpleBoxShape shape = (SimpleBoxShape) body.shape();
            float frontZ = shape.z() / 2;
            float zTolerance = frontZ / 4f;
            if (Util.equals(localPoint.z, frontZ, zTolerance)) {
                // top surface only, ignore sides and back
                this.mousePick = r.hitPointWorld;
                fingered = finger;
                return fingered.on(front, localPoint.x / shape.x() + 0.5f, localPoint.y / shape.y() + 0.5f, buttons);
            // return mouseFront.update(null, localPoint.x, localPoint.y, buttons);
            }
        } else {
            if (fingered != null && fingered.off()) {
                fingered = null;
            }
        }
    }
    return null;
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial) SimpleBoxShape(spacegraph.space3d.phys.shape.SimpleBoxShape) Transform(spacegraph.space3d.phys.math.Transform) spacegraph.util.math.v3(spacegraph.util.math.v3) Surface(spacegraph.space2d.Surface)

Example 5 with SimpleSpatial

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

the class ForceDirected method repel.

private static void repel(Collidable x, Collidable y, float speed, float maxDist) {
    SimpleSpatial xp = ((SimpleSpatial) x.data());
    if (xp == null)
        return;
    SimpleSpatial yp = ((SimpleSpatial) y.data());
    if (yp == null)
        return;
    v3 delta = v();
    delta.sub(xp.transform(), yp.transform());
    float len = delta.normalize();
    len -= (xp.radius() + yp.radius());
    if (len < 0)
        len = 0;
    else if (len >= maxDist)
        return;
    float s = speed / (1 + (len * len));
    v3 v = v(delta.x * s, delta.y * s, delta.z * s);
    ((Body3D) x).velAdd(v);
    v.negate();
    ((Body3D) y).velAdd(v);
}
Also used : SimpleSpatial(spacegraph.space3d.SimpleSpatial) Body3D(spacegraph.space3d.phys.Body3D) spacegraph.util.math.v3(spacegraph.util.math.v3)

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