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);
}
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();
}
}
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);
}
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;
}
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);
}
Aggregations