Search in sources :

Example 1 with Spatial

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

the class OrbMouse method mouseMotionFunc.

// public ClosestRay mousePick(int sx, int sy) {
// return mousePick(space.rayTo(sx, sy));
// }
// 
// public ClosestRay mousePick(v3 rayTo) {
// ClosestRay r = this.rayCallback;
// 
// //v3 camPos = v(rayTo.x, rayTo.y, space.camPos.z); //project directly upward
// 
// v3 camPos = space.camPos;
// 
// return r;
// }
@Deprecated
private /* TODO probably rewrite */
boolean mouseMotionFunc(int px, int py, short[] buttons) {
    ClosestRay cray = mousePick(px, py);
    /*System.out.println(mouseTouch.collisionObject + " touched with " +
            Arrays.toString(buttons) + " at " + mouseTouch.hitPointWorld
        );*/
    Spatial prevPick = pickedSpatial;
    Spatial pickedSpatial = null;
    picked = cray != null ? cray.collidable : null;
    if (picked != null) {
        Object t = picked.data();
        if (t instanceof Spatial) {
            pickedSpatial = ((Spatial) t);
            if (pickedSpatial.onTouch(finger, picked, cray, buttons, space) != null) {
                // absorbed surface
                clearDrag();
            } else {
            // maybe find next closest?
            }
        }
    }
    if ((pickConstraint != null)) /*|| (directDrag != null)*/
    {
    // // keep it at the same picking distance
    // v3 eyePos = v(space.camPos);
    // v3 dir = v();
    // dir.sub(cray.rayFromWorld, eyePos);
    // dir.normalize();
    // dir.scale(gOldPickingDist);
    // 
    // v3 newPos = v();
    // newPos.add(eyePos, dir);
    // if (directDrag != null) {
    // //directly move the 'static' object
    // 
    // Object u = directDrag.data();
    // 
    // //System.out.println("DRAG: " + directDrag + " " + u + " -> " + newPos);
    // 
    // if (u instanceof SimpleSpatial) {
    // ((SimpleSpatial) u).motionLock(true);
    // }
    // 
    // //                MotionState mm = directDrag.getMotionState();
    // //                if (mm instanceof Motion) {
    // //                    ((Motion) mm).center(newPos);
    // //                }
    // directDrag.worldTransform.set(newPos);
    // 
    // return true;
    // } else
    // v3 newRayTo = new v3(mousePick(px, py).rayToWorld); //HACK dont involve a complete ClosestRay
    // v3 eyePos = new v3(space.camPos);
    // v3 dir = new v3();
    // dir.sub(newRayTo, eyePos);
    // dir.normalize();
    // dir.scale(gOldPickingDist);
    // 
    // v3 newPos = new v3();
    // newPos.add(eyePos, dir);
    // 
    // // move the constraint pivot
    // Point2PointConstraint p2p = (Point2PointConstraint) pickConstraint;
    // p2p.setPivotB(newPos);
    // return true;
    } else {
    // if (mouseDragPrevX >= 0) {
    // 
    // 
    // ///only if ALT key is pressed (Maya style)
    // //            if (m_modifierKeys & BT_ACTIVE_ALT)
    // //            {
    // //                if (m_mouseButtons & 4) {
    // //                    btVector3 hor = getRayTo(0, 0) - getRayTo(1, 0);
    // //                    btVector3 vert = getRayTo(0, 0) - getRayTo(0, 1);
    // //                    btScalar multiplierX = btScalar(0.001);
    // //                    btScalar multiplierY = btScalar(0.001);
    // //                    if (m_ortho) {
    // //                        multiplierX = 1;
    // //                        multiplierY = 1;
    // //                    }
    // //
    // //
    // //                    m_cameraTargetPosition += hor * dx * multiplierX;
    // //                    m_cameraTargetPosition += vert * dy * multiplierY;
    // //                }
    // //            }
    // 
    // for (short b : buttons) {
    // switch (b) {
    // case 1:
    // //                                ClosestRay m = mousePick(x, y, null);
    // //                                if (!m.hasHit()) {
    // //                                    //drag on background space
    // //                                    float px = mouseDragDX * 0.1f;
    // //                                    float py = mouseDragDY * 0.1f;
    // //
    // //                                    //TODO finish:
    // //
    // //                                    //v3 vx = v().cross(camDir, camUp);
    // //                                    //vx.normalize();
    // //                                    //System.out.println(px + " " + py + " " + camDir + " x " + camUp + " " + vx);
    // //
    // //                                    //camPosTarget.scaleAdd(px, vx);
    // //                                    //camPosTarget.scaleAdd(py, camUp);
    // //                                }
    // return true;
    // case 3:
    // //right mouse drag = rotate
    // //                        nextAzi += dx * btScalar(0.2);
    // //                        nextAzi = fmodf(nextAzi, btScalar(360.f));
    // //                        nextEle += dy * btScalar(0.2);
    // //                        nextEle = fmodf(nextEle, btScalar(180.f));
    // //space.azi.setValue(space.azi.floatValue() + mouseDragDX * 0.2f );
    // //nextAzi = fmodf(nextAzi, btScalar(360.f));
    // //space.ele.setValue(space.ele.floatValue() + mouseDragDY * (0.2f));
    // //nextEle = fmodf(nextEle, btScalar(180.f));
    // return true;
    // case 2:
    // //middle mouse drag = zoom
    // 
    // //space.setCameraDistance( space.cameraDistance.floatValue() - mouseDragDY * 0.5f );
    // return true;
    // }
    // }
    // }
    // 
    }
    if (prevPick != pickedSpatial) {
        if (prevPick != null) {
            prevPick.onUntouch(space);
        }
        this.pickedSpatial = pickedSpatial;
    }
    return false;
}
Also used : Spatial(spacegraph.space3d.Spatial) ClosestRay(spacegraph.space3d.phys.collision.ClosestRay)

Example 2 with Spatial

use of spacegraph.space3d.Spatial 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 3 with Spatial

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

the class ForceDirected method solve.

@Override
public void solve(Broadphase b, List<Collidable> objects, float timeStep) {
    int n = objects.size();
    if (n == 0)
        return;
    for (int iter = 0; iter < iterations; iter++) {
        objects.forEach(c -> {
            Spatial x = ((Spatial) c.data());
            if (x != null)
                x.stabilize(boundsMin, boundsMax);
        });
        // System.out.print("Force direct " + objects.size() + ": ");
        // final int[] count = {0};
        // count[0] += l.size();
        // System.out.print(l.size() + "  ");
        int clusters = (int) Math.ceil(/*Math.log*/
        (((float) n) / 32));
        if (clusters % 2 == 0)
            // odd to break symmetry
            clusters++;
        b.forEach((int) Math.ceil((float) n / clusters), objects, this::batch);
        if (center) {
            float cx = 0, cy = 0, cz = 0;
            for (int i = 0, objectsSize = n; i < objectsSize; i++) {
                v3 c = objects.get(i).transform;
                cx += c.x;
                cy += c.y;
                cz += c.z;
            }
            cx /= -n;
            cy /= -n;
            cz /= -n;
            v3 correction = v3.v(cx, cy, cz);
            if (correction.lengthSquared() > centerSpeed * centerSpeed)
                correction.normalize(centerSpeed);
            for (int i = 0, objectsSize = n; i < objectsSize; i++) {
                objects.get(i).transform.add(correction);
            }
        }
    }
}
Also used : Spatial(spacegraph.space3d.Spatial) SimpleSpatial(spacegraph.space3d.SimpleSpatial) spacegraph.util.math.v3(spacegraph.util.math.v3)

Aggregations

Spatial (spacegraph.space3d.Spatial)3 SimpleSpatial (spacegraph.space3d.SimpleSpatial)2 Collidable (spacegraph.space3d.phys.Collidable)1 ClosestRay (spacegraph.space3d.phys.collision.ClosestRay)1 SpaceWidget (spacegraph.space3d.widget.SpaceWidget)1 spacegraph.util.math.v3 (spacegraph.util.math.v3)1