Browse files

Remove old physics engines which I don't plan to support with the ver…

…let refactor
  • Loading branch information...
1 parent 4d1569f commit 6afad8b1e14fc6fc7e8eb24e790a74cb4275dcb8 @xaviershay xaviershay committed Oct 4, 2008
View
5 physics_engine/Chaotic.config
@@ -1,5 +0,0 @@
-# name of the engine class
-name=PhysicsEngineChaotic
-
-# parameters specific to this engine
-drag=0.00001
View
9 physics_engine/Legacy.config
@@ -1,9 +0,0 @@
-# name of the engine class
-name=PhysicsEngineLegacy
-
-# parameters specific to this engine
-edgeMultiplier=1.0
-calculationRandomizer=0.01
-nodesMultiplier=1.0
-speedMultiplier=1.0
-drag=0.5
View
9 physics_engine/MaxwellsDemon.config
@@ -1,9 +0,0 @@
-# name of the engine class
-name=PhysicsEngineMaxwellsDemon
-
-# parameters specific to this engine
-drag=0.00001
-
-doorSize=100
-doorWayLeft=10
-doorWayRight=50
View
8 physics_engine/Simple.config
@@ -1,8 +0,0 @@
-# name of the engine class
-name=PhysicsEngineSimple
-
-# parameters specific to this engine
-edgeMultiplier=1.0
-speedMultiplier=1.0
-nodesMultiplier=1.0
-drag=0.05
View
328 src/PhysicsEngineChaotic.java
@@ -1,328 +0,0 @@
-/**
- * Copyright 2008 code_swarm project team
- *
- * This file is part of code_swarm.
- *
- * code_swarm is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * code_swarm 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
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with code_swarm. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import javax.vecmath.Vector2f;
-
-/**
- * @brief Physics Engine implementation. In essence, people bounce around. Nodes are attracted to the people.
- *
- * @see PhysicsEngine for interface information
- * @author Desmond Daignault <nawglan at gmail>
- */
-public class PhysicsEngineChaotic extends PhysicsEngine
-{
- private CodeSwarmConfig cfg;
-
- private float DRAG;
-
-
- /**
- * Method for initializing parameters.
- * @param p Properties from the config file.
- */
- public void setup (CodeSwarmConfig p)
- {
- cfg = p;
- DRAG = cfg.getFloatProperty("drag",0.00001);
- }
-
- /**
- * Legacy method that calculate the attractive/repulsive force between a person and one of its file along their link (the edge).
- *
- * @param edge the link between a person and one of its file
- * @return force force calculated between those two nodes
- */
- private Vector2f calculateForceAlongAnEdge( code_swarm.Edge edge )
- {
- float distance;
- float deltaDistance;
- Vector2f force = new Vector2f();
- Vector2f tforce = new Vector2f();
-
- // distance calculation
- tforce.sub(edge.nodeTo.mPosition, edge.nodeFrom.mPosition);
- distance = tforce.length();
- if (distance > 0) {
- // force calculation (increase when distance is different from targeted len")
- deltaDistance = (edge.len - distance) / (distance * 3);
- // force ponderation using a re-mapping life from 0-255 scale to 0-1.0 range
- // This allows nodes to drift apart as their life decreases.
- deltaDistance *= ((float)edge.life / edge.LIFE_INIT);
-
- // force projection onto x and y axis
- tforce.scale(deltaDistance);
-
- force.set(tforce);
- }
-
- return force;
- }
-
- private void checkCollisionNew(code_swarm.Node nodeA, code_swarm.Node nodeB, float maxD)
- {
- Vector2f tmp = new Vector2f();
- tmp.sub(nodeA.mPosition, nodeB.mPosition);
- double distance = tmp.length();
- if (distance <= (nodeA.mass + nodeB.mass)) {
- float dx = nodeA.mPosition.x - nodeB.mPosition.x;
- float dy = nodeA.mPosition.y - nodeB.mPosition.y;
- float collision_angle = (float)Math.atan2(dx,dy);
- float magnitude1 = nodeA.mSpeed.length();
- float magnitude2 = nodeB.mSpeed.length();
- float direction1 = (float)Math.atan2(nodeA.mSpeed.y, nodeA.mSpeed.x);
- float direction2 = (float)Math.atan2(nodeB.mSpeed.y, nodeB.mSpeed.x);
- float new_xspeed1 = magnitude1 * (float)Math.cos(direction1 - collision_angle);
- float final_yspeed1 = magnitude1 * (float)Math.sin(direction1 - collision_angle);
- float new_xspeed2 = magnitude2 * (float)Math.cos(direction2 - collision_angle);
- float final_yspeed2 = magnitude2 * (float)Math.sin(direction2 - collision_angle);
- float final_xspeed1 = ((nodeA.mass-nodeB.mass)*new_xspeed1+(nodeB.mass+nodeB.mass)*new_xspeed2)/(nodeA.mass+nodeB.mass);
- float final_xspeed2 = ((nodeA.mass+nodeA.mass)*new_xspeed1+(nodeB.mass-nodeA.mass)*new_xspeed2)/(nodeA.mass+nodeB.mass);
-
- float nodeA_xspeed = (float)(Math.cos(collision_angle)*final_xspeed1+Math.cos(collision_angle+Math.PI/2)*final_yspeed1);
- float nodeA_yspeed = (float)(Math.sin(collision_angle)*final_xspeed1+Math.sin(collision_angle+Math.PI/2)*final_yspeed1);
- float nodeB_xspeed = (float)(Math.cos(collision_angle)*final_xspeed2+Math.cos(collision_angle+Math.PI/2)*final_yspeed2);
- float nodeB_yspeed = (float)(Math.sin(collision_angle)*final_xspeed2+Math.sin(collision_angle+Math.PI/2)*final_yspeed2);
-
- nodeA.mSpeed.set(nodeA_xspeed,nodeA_yspeed);
- nodeB.mSpeed.set(nodeB_xspeed,nodeB_yspeed);
- }
- }
-
- private void checkCollision(code_swarm.Node nodeA, code_swarm.Node nodeB, float maxD)
- {
- Vector2f dVec = new Vector2f();
-
- dVec.sub(nodeB.mPosition, nodeA.mPosition);
- double d = dVec.length();
- if (d <= (maxD)) { // Yep, a collision
- dVec.normalize();
- float Vp1 = nodeA.mSpeed.dot(dVec);
- float Vp2 = nodeB.mSpeed.dot(dVec);
- float dt = (float) ((nodeA.mass + nodeB.mass - d)/(Vp1 + Vp2));
- nodeA.mPosition.set(nodeA.mPosition.x - nodeA.mSpeed.x * dt, nodeA.mPosition.y - nodeA.mSpeed.y * dt);
- nodeB.mPosition.set(nodeB.mPosition.x - nodeB.mSpeed.x * dt, nodeB.mPosition.y - nodeB.mSpeed.y * dt);
- dVec.sub(nodeB.mPosition, nodeA.mPosition);
- d = dVec.length();
- dVec.normalize();
- float Va1 = nodeA.mSpeed.dot(dVec);
- float Va2 = nodeB.mSpeed.dot(dVec);
- float Vb1 = (-nodeA.mSpeed.x * dVec.y + nodeA.mSpeed.y * dVec.x);
- float Vb2 = (-nodeB.mSpeed.x * dVec.y + nodeB.mSpeed.y * dVec.x);
-
- float ed = 1; // ed <= 1, for elastic collision ed = 1
- float vap1 = Va1 + (1 + ed) * (Va2 - Va1) / (1 + nodeA.mass / nodeB.mass);
- float vap2 = Va2 + (1 + ed) * (Va1 - Va2) / (1 + nodeB.mass / nodeA.mass);
-
- nodeA.mSpeed.x = vap1*dVec.x - Vb1*dVec.y;
- nodeA.mSpeed.y = vap1*dVec.y + Vb1*dVec.x;
- nodeB.mSpeed.x = vap2*dVec.x - Vb2*dVec.y;
- nodeB.mSpeed.y = vap2*dVec.y + Vb2*dVec.x;
-
- nodeA.mPosition.x += nodeA.mSpeed.x * dt;
- nodeA.mPosition.y += nodeA.mSpeed.y * dt;
- nodeB.mPosition.x += nodeB.mSpeed.x * dt;
- nodeB.mPosition.y += nodeB.mSpeed.y * dt;
- }
- }
-
-
- /**
- * Legacy method that calculate the repulsive force between two similar nodes (either files or persons).
- *
- * @param nodeA [in]
- * @param nodeB [in]
- */
- private void calculateForceBetweenfNodes( code_swarm.FileNode nodeA, code_swarm.FileNode nodeB )
- {
- checkCollisionNew(nodeA, nodeB, 5);
- }
-
- /**
- * Legacy method that calculate the repulsive force between two similar nodes (either files or persons).
- *
- * @param nodeA [in]
- * @param nodeB [in]
- */
- private void calculateForceBetweenpNodes( code_swarm.PersonNode nodeA, code_swarm.PersonNode nodeB )
- {
- checkCollisionNew(nodeA, nodeB, 50);
- }
-
-
- /**
- * Legacy method that apply a force to a node, converting acceleration to speed.
- *
- * @param node [in] Node the node to which the force apply
- * @param force [in] force a force Vector representing the force on a node
- *
- * TODO: does force should be a property of the node (or not?)
- */
- private void applyForceTo( code_swarm.Node node, Vector2f force )
- {
- double dlen;
- Vector2f mod = new Vector2f(force);
-
- /**
- * Taken from Newton's 2nd law. F=ma
- */
- dlen = mod.length();
- if (dlen > 0) {
- mod.scale(node.mass);
- node.mSpeed.add(mod);
- }
- }
-
- /**
- * Legacy method that apply a force to a node, converting acceleration to speed.
- *
- * @param node the node to which the force apply
- */
- protected void applySpeedTo( code_swarm.Node node )
- {
- // This block enforces a maximum absolute velocity.
- if (node.mSpeed.length() > node.maxSpeed) {
- Vector2f mag = new Vector2f(node.mSpeed.x / node.maxSpeed, node.mSpeed.y / node.maxSpeed);
- node.mSpeed.scale(1/mag.lengthSquared());
- }
-
- // This block convert Speed to Position
- node.mPosition.add(node.mSpeed);
- }
-
- /**
- * Method that allows Physics Engine to modify forces between files and people during the relax stage
- *
- * @param edge the edge to which the force apply (both ends)
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.Edge edge) {
- // Calculate force between the node "from" and the node "to"
- Vector2f force = calculateForceAlongAnEdge(edge);
-
- // transmit force projection to file and person nodes
- force.negate();
- applyForceTo(edge.nodeFrom, force); // fNode: attract fNode to pNode
- applySpeedTo(edge.nodeFrom); // fNode: move it.
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param fNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.FileNode fNode ) {
- // Calculation of repulsive force between files
- for (code_swarm.FileNode n : code_swarm.getLivingNodes()) {
- if (n != fNode) {
- // elemental force calculation, and summation
- calculateForceBetweenfNodes(fNode, n);
- }
- }
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the update phase.
- *
- * @param fNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onUpdate(code_swarm.FileNode fNode) {
- // Apply Speed to Position on nodes
- applySpeedTo(fNode);
-
- // ensure coherent resulting position
- fNode.mPosition.set(constrain(fNode.mPosition.x, 0.0f, (float)code_swarm.width),constrain(fNode.mPosition.y, 0.0f, (float)code_swarm.height));
-
- fNode.decay();
-
- // Apply drag (reduce Speed for next frame calculation)
- fNode.mSpeed.scale(DRAG);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param pNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.PersonNode pNode) {
- if (pNode.mSpeed.length() == 0) {
- // Range (-1,1)
- pNode.mSpeed.set(pNode.mass*((float)Math.random()-pNode.mass),pNode.mass*((float)Math.random()-pNode.mass));
- }
-
- pNode.mSpeed.scale(pNode.mass);
- pNode.mSpeed.normalize();
- pNode.mSpeed.scale(4);
-
- float distance = pNode.mSpeed.length();
- if (distance > 0) {
- float deltaDistance = (pNode.mass - distance) / (distance * 2);
- deltaDistance *= ((float)pNode.life / pNode.LIFE_INIT);
-
- pNode.mSpeed.scale(deltaDistance);
- }
-
- applySpeedTo(pNode);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the update phase.
- *
- * @param pNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onUpdate(code_swarm.PersonNode pNode) {
- // Check for collisions with neighbors.
- for (code_swarm.PersonNode p : code_swarm.getLivingPeople()) {
- if (pNode != p) {
- calculateForceBetweenpNodes(pNode,p);
- }
- }
-
- // ensure coherent resulting position
- pNode.mPosition.set(constrain(pNode.mPosition.x, 0.0f, (float)code_swarm.width),constrain(pNode.mPosition.y, 0.0f, (float)code_swarm.height));
-
- if ((pNode.mPosition.x < pNode.mass && pNode.mSpeed.x < 0.0f) || (pNode.mPosition.x > (code_swarm.width - pNode.mass) && pNode.mSpeed.x > 0.0f)) {
- // we hit a vertical wall
- pNode.mSpeed.x = -pNode.mSpeed.x;
- while (pNode.mPosition.x < pNode.mass || pNode.mPosition.x > (code_swarm.width - pNode.mass)) {
- pNode.mPosition.x += pNode.mSpeed.x;
- }
- }
- if ((pNode.mPosition.y < pNode.mass && pNode.mSpeed.y < 0.0f) || (pNode.mPosition.y > (code_swarm.height - pNode.mass) && pNode.mSpeed.y > 0.0f)) {
- // we hit a horizontal wall
- pNode.mSpeed.y = -pNode.mSpeed.y;
- while (pNode.mPosition.y < pNode.mass || pNode.mPosition.y > (code_swarm.height - pNode.mass)) {
- pNode.mPosition.y += pNode.mSpeed.y;
- }
- }
- // shortening life
- pNode.decay();
-
- // Apply drag (reduce Speed for next frame calculation)
- pNode.mSpeed.scale(DRAG);
- }
-}
View
215 src/PhysicsEngineLegacy.java
@@ -1,215 +0,0 @@
-/**
- * Copyright 2008 code_swarm project team
- *
- * This file is part of code_swarm.
- *
- * code_swarm is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * code_swarm 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
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with code_swarm. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import javax.vecmath.Vector2f;
-
-/**
- * @brief Legacy algorithms describing all physicals interactions between nodes (files and persons)
- *
- * This is only a rewriting of the initial code_swarm prototype.
- *
- * @see PhysicsEngine Physical Engine Interface
- */
-public class PhysicsEngineLegacy extends PhysicsEngine
-{
- private CodeSwarmConfig cfg;
-
- private float FORCE_EDGE_MULTIPLIER;
- private float FORCE_CALCULATION_RANDOMIZER;
- private float FORCE_NODES_MULTIPLIER;
- private float FORCE_TO_SPEED_MULTIPLIER;
-
- /**
- * Method for initializing parameters.
- * @param p The CodeSwarmConfig for this code_swarm instance
- */
- //PhysicalEngineLegacy(float forceEdgeMultiplier, float forceCalculationRandomizer, float forceToSpeedMultiplier, float speedToPositionDrag)
- public void setup (CodeSwarmConfig p)
- {
- cfg = p;
- FORCE_EDGE_MULTIPLIER = cfg.getFloatProperty("edgeMultiplier", 1.0);
- FORCE_CALCULATION_RANDOMIZER = cfg.getFloatProperty("calculationRandomizer",0.01);
- FORCE_NODES_MULTIPLIER = cfg.getFloatProperty("nodesMultiplier",1.0);
- FORCE_TO_SPEED_MULTIPLIER = cfg.getFloatProperty("speedMultiplier",1.0);
- SPEED_TO_POSITION_MULTIPLIER = cfg.getFloatProperty("drag",0.5);
- }
-
- /**
- * Legacy method that calculate the attractive/repulsive force between a person and one of its file along their link (the edge).
- *
- * @param edge the link between a person and one of its file
- * @return force force calculated between those two nodes
- */
- private Vector2f calculateForceAlongAnEdge( code_swarm.Edge edge )
- {
- float distance;
- float deltaDistance;
- Vector2f force = new Vector2f();
- Vector2f tforce = new Vector2f();
-
- // distance calculation
- tforce.sub(edge.nodeTo.mPosition, edge.nodeFrom.mPosition);
- distance = tforce.length();
- if (distance > 0) {
- // force calculation (increase when distance is different from targeted len")
- deltaDistance = (edge.len - distance) / (distance * 3);
- // force ponderation using a re-mapping life from 0-255 scale to 0-1.0 range
- // This allows nodes to drift apart as their life decreases.
- deltaDistance *= ((float)edge.life / edge.LIFE_INIT);
-
- // force projection onto x and y axis
- tforce.scale(deltaDistance*FORCE_EDGE_MULTIPLIER);
-
- force.set(tforce);
- }
-
- return force;
- }
-
- /**
- * Legacy method that calculate the repulsive force between two similar nodes (either files or persons).
- *
- * @param nodeA [in]
- * @param nodeB [in]
- * @return force force calculated between those two nodes
- */
- private Vector2f calculateForceBetweenNodes( code_swarm.Node nodeA, code_swarm.Node nodeB )
- {
- float lensq;
- Vector2f force = new Vector2f();
- Vector2f normVec = new Vector2f();
-
- /**
- * Get the distance between nodeA and nodeB
- */
- normVec.sub(nodeA.mPosition, nodeB.mPosition);
- lensq = normVec.lengthSquared();
- /**
- * If there is a Collision. This is assuming a radius of zero.
- * if (lensq == (radius1 + radius2)) is what to use if we have radius
- * could use touches for files and edge_length for people?
- */
- if (lensq == 0) {
- force.set( (float)Math.random()*FORCE_CALCULATION_RANDOMIZER, (float)Math.random()*FORCE_CALCULATION_RANDOMIZER );
- } else if (lensq < 10000) {
- /**
- * No collision and distance is close enough to actually matter.
- */
- normVec.scale(FORCE_NODES_MULTIPLIER/lensq);
- force.set(normVec);
- }
-
- return force;
- }
-
- /**
- * Legacy method that apply a force to a node, converting acceleration to speed.
- *
- * @param node [in] Node the node to which the force apply
- * @param force [in] force a force Vector representing the force on a node
- *
- * TODO: does force should be a property of the node (or not?)
- */
- private void applyForceTo( code_swarm.Node node, Vector2f force )
- {
- float dlen;
- Vector2f mod = new Vector2f(force);
-
- /**
- * Taken from Newton's 2nd law. F=ma
- */
- dlen = mod.length();
- if (dlen > 0) {
- mod.scale(node.mass * FORCE_TO_SPEED_MULTIPLIER);
- node.mSpeed.add(mod);
- }
- }
-
-
- /**
- * Method that allows Physics Engine to modify forces between files and people during the relax stage
- *
- * @param edge the edge to which the force apply (both ends)
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.Edge edge) {
- Vector2f force = new Vector2f();
-
- // Calculate force between the node "from" and the node "to"
- force = calculateForceAlongAnEdge(edge);
-
- // transmit (applying) fake force projection to file and person nodes
- applyForceTo(edge.nodeTo, force);
- force.negate(); // force is inverted for the other end of the edge
- applyForceTo(edge.nodeFrom, force);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param fNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.FileNode fNode ) {
- Vector2f forceBetweenFiles = new Vector2f();
- Vector2f forceSummation = new Vector2f();
-
- // Calculation of repulsive force between persons
- for (code_swarm.FileNode n : code_swarm.getLivingNodes()) {
- if (n != fNode) {
- // elemental force calculation, and summation
- forceBetweenFiles = calculateForceBetweenNodes(fNode, n);
- forceSummation.add(forceBetweenFiles);
- }
- }
- // Apply repulsive force from other files to this Node
- applyForceTo(fNode, forceSummation);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param pNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.PersonNode pNode) {
- Vector2f forceBetweenPersons = new Vector2f();
- Vector2f forceSummation = new Vector2f();
-
- // Calculation of repulsive force between persons
- for (code_swarm.PersonNode p : code_swarm.getLivingPeople()) {
- if (p != pNode) {
- // elemental force calculation, and summation
- forceBetweenPersons = calculateForceBetweenNodes(pNode, p);
- forceSummation.add(forceBetweenPersons);
- }
- }
- // Apply repulsive force from other persons to this Node
- applyForceTo(pNode, forceSummation);
-
- // Don't know why, but the prototype had this.
- pNode.mSpeed.scale(1.0f/12);
- }
-
-
-}
-
View
578 src/PhysicsEngineMaxwellsDemon.java
@@ -1,578 +0,0 @@
-/**
- * Copyright 2008 code_swarm project team
- *
- * This file is part of code_swarm.
- *
- * code_swarm is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * code_swarm 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
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with code_swarm. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import javax.vecmath.Vector2f;
-
-/**
- * @brief Physics Engine implementation. In essence, people bounce around. Nodes are attracted to the people.
- *
- * @see PhysicsEngine for interface information
- * @author Desmond Daignault <nawglan at gmail>
- */
-public class PhysicsEngineMaxwellsDemon extends PhysicsEngine
-{
- /**
- *
- */
- private static final long serialVersionUID = 1L;
-
- private CodeSwarmConfig cfg;
-
- private float DRAG;
- private Integer doorSize;
- private boolean doorOpen;
- private int midWayX;
- private int midWayY;
- private int startDoorY;
- Vector2f doorCenter;
- private int doorWayLeft;
- private int doorWayRight;
-
-
- /**
- * Method for initializing parameters.
- * @param p Properties from the config file.
- */
- public void setup (CodeSwarmConfig p)
- {
- cfg = p;
- DRAG = cfg.getFloatProperty("drag",0.00001);
- doorSize = cfg.getIntProperty("doorSize",100);
- doorOpen = false;
- midWayX = code_swarm.width / 2;
- midWayY = code_swarm.height / 2;
- startDoorY = midWayY - doorSize;
- doorCenter = new Vector2f(midWayX, midWayY);
- doorWayLeft = cfg.getIntProperty("doorWayLeft",35);
- doorWayRight = cfg.getIntProperty("doorWayRight",50);
- }
-
- /**
- *
- * @param opened Is door open or closed?
- */
- private void drawWall() {
- // Draw the wall.
- int midWayX = code_swarm.width / 2;
- int midWayY = code_swarm.height / 2;
- int startDoorY = midWayY - doorSize;
-
- // draw top of wall
- code_swarm.utils.drawLine(midWayX, 0, midWayX, midWayY, 255, 255, 255);
-
- // draw door
- if (doorOpen) {
- code_swarm.utils.drawLine(midWayX, startDoorY, midWayX, midWayY, 0, 255, 0);
- } else {
- code_swarm.utils.drawLine(midWayX, startDoorY, midWayX, midWayY, 255, 0, 0);
- }
- // draw bottom of wall
- code_swarm.utils.drawLine(midWayX, midWayY, midWayX, code_swarm.height, 255, 255, 255);
- }
-
- /**
- * Calculate the attractive/repulsive force between a person and one of its file
- * along their link (the edge).
- *
- * @param edge the link between a person and one of its file
- * @return Vector2f force calculated between those two nodes
- */
- private Vector2f calculateForceAlongAnEdge( code_swarm.Edge edge )
- {
- float distance;
- float deltaDistance;
- Vector2f force = new Vector2f();
- Vector2f tforce = new Vector2f();
-
- // distance calculation
- tforce.sub(edge.nodeTo.mPosition, edge.nodeFrom.mPosition);
- distance = tforce.length();
- if (distance > 0) {
- // force calculation (increase when distance is different from targeted len")
- deltaDistance = (edge.len - distance) / (distance * 3);
- // force ponderation using a re-mapping life from 0-255 scale to 0-1.0 range
- // This allows nodes to drift apart as their life decreases.
- deltaDistance *= ((float)edge.life / edge.LIFE_INIT);
-
- // force projection onto x and y axis
- tforce.scale(deltaDistance);
-
- force.set(tforce);
- }
-
- return force;
- }
-
- /**
- * Calculate the repulsive force between two similar file nodes.
- *
- * @param nodeA
- * @param nodeB
- * @return Vector2f force calculated between those two nodes
- */
- private Vector2f calculateForceBetweenfNodes( code_swarm.FileNode nodeA, code_swarm.FileNode nodeB )
- {
- float distance;
- Vector2f force = new Vector2f();
- Vector2f normVec = new Vector2f();
-
- /**
- * Get the distance between nodeA and nodeB
- */
- normVec.sub(nodeA.mPosition, nodeB.mPosition);
- distance = normVec.lengthSquared();
- /**
- * If there is a Collision. This is assuming a radius of zero.
- * if (lensq == (radius1 + radius2)) is what to use if we have radius
- * could use touches for files and edge_length for people?
- */
- if (distance == (nodeA.touches + nodeB.touches)) {
- force.set(0.01f* (((float)Math.random()*2)-1), (0.01f* ((float)Math.random()*2)-1));
- } else if (distance < 10000) {
- /**
- * No collision and distance is close enough to actually matter.
- */
- normVec.scale(1/distance);
- force.set(normVec);
- }
-
- return force;
- }
-
- /**
- * Calculate the repulsive force between two similar person nodes
- * People ricochet off of each other and walls.
- *
- * @param nodeA
- * @param nodeB
- * @return Vector2f force calculated between those two nodes
- */
- private Vector2f calculateForceBetweenpNodes( code_swarm.PersonNode nodeA, code_swarm.PersonNode nodeB )
- {
- Vector2f force = new Vector2f();
- Vector2f tmp = new Vector2f();
-
- tmp.sub(nodeA.mPosition, nodeB.mPosition);
- double distance = Math.sqrt(tmp.lengthSquared());
- if (distance <= (nodeA.mass + nodeB.mass)) {
- if (nodeA.mSpeed.x > 0 && nodeA.mSpeed.y > 0) { // Node A down and right
- if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y > 0) { // Node B down and left
- nodeA.mSpeed.x *= -1;
- nodeB.mSpeed.x *= -1;
- } else if (nodeB.mSpeed.x > 0 && nodeB.mSpeed.y < 0) { // Node B up and right
- nodeA.mSpeed.y *= -1;
- nodeB.mSpeed.y *= -1;
- } else if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y < 0) { // Node B up and left
- nodeA.mSpeed.negate();
- nodeB.mSpeed.negate();
- } else { // Node B down and right
- nodeB.mSpeed.x *= -1;
- nodeA.mSpeed.x *= 2;
- }
- } else if (nodeA.mSpeed.x > 0 && nodeA.mSpeed.y < 0) { // Node A up and right
- if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y > 0) { // Node B down and left
- nodeA.mSpeed.negate();
- nodeB.mSpeed.negate();
- } else if (nodeB.mSpeed.x > 0 && nodeB.mSpeed.y < 0) { // Node B up and right
- nodeA.mSpeed.x *= -1;
- nodeB.mSpeed.x *= 2;
- } else if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y < 0) { // Node B up and left
- nodeA.mSpeed.x *= -1;
- nodeB.mSpeed.x *= -1;
- } else { // Node B down and right
- nodeA.mSpeed.y *= -1;
- nodeB.mSpeed.y *= -1;
- }
- } else if (nodeA.mSpeed.x < 0 && nodeA.mSpeed.y > 0) { // Node A down and left
- if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y > 0) { // Node B down and left
- nodeB.mSpeed.x *= -1;
- nodeA.mSpeed.x *= 2;
- } else if (nodeB.mSpeed.x > 0 && nodeB.mSpeed.y < 0) { // Node B up and right
- nodeA.mSpeed.negate();
- nodeB.mSpeed.negate();
- } else if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y < 0) { // Node B up and left
- nodeA.mSpeed.y *= -1;
- nodeB.mSpeed.y *= -1;
- } else { // Node B down and right
- nodeA.mSpeed.x *= -1;
- nodeB.mSpeed.x *= -1;
- }
- } else { // Node A up and left
- if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y > 0) { // Node B down and left
- nodeA.mSpeed.y *= -1;
- nodeB.mSpeed.y *= -1;
- } else if (nodeB.mSpeed.x > 0 && nodeB.mSpeed.y < 0) { // Node B up and right
- nodeA.mSpeed.x *= -1;
- nodeB.mSpeed.x *= -1;
- } else if (nodeB.mSpeed.x < 0 && nodeB.mSpeed.y < 0) { // Node B up and left
- nodeA.mSpeed.x *= -1;
- nodeB.mSpeed.x *= 2;
- } else { // Node B down and right
- nodeA.mSpeed.negate();
- nodeB.mSpeed.negate();
- }
- }
- while (distance <= (nodeA.mass + nodeB.mass)) {
- applySpeedTo(nodeA);
- constrainNode(nodeA, whichSide(nodeA));
- applySpeedTo(nodeB);
- constrainNode(nodeB, whichSide(nodeB));
- tmp.sub(nodeA.mPosition, nodeB.mPosition);
- distance = Math.sqrt(tmp.lengthSquared());
- }
- }
- /**
- * No collision
- */
- return force;
- }
-
- /**
- * Apply force to a node, converting acceleration to speed.
- *
- * @param node Node the node to which the force apply
- * @param force force a force Vector representing the force on a node
- *
- * TODO: does force should be a property of the node (or not?)
- */
- private void applyForceTo( code_swarm.Node node, Vector2f force )
- {
- double dlen;
- Vector2f mod = new Vector2f(force);
-
- /**
- * Taken from Newton's 2nd law. F=ma
- */
- dlen = mod.length();
- if (dlen > 0) {
- mod.scale(node.mass);
- node.mSpeed.add(mod);
- }
- }
-
- /**
- * Apply force to a node, converting speed to position.
- *
- * @param node the node to which the force apply
- */
- protected void applySpeedTo( code_swarm.Node node )
- {
- // This block enforces a maximum absolute velocity.
- if (node.mSpeed.length() > node.maxSpeed) {
- Vector2f mag = new Vector2f(node.mSpeed.x / node.maxSpeed, node.mSpeed.y / node.maxSpeed);
- node.mSpeed.scale(1/mag.lengthSquared());
- }
-
- // This block convert Speed to Position
- node.mPosition.add(node.mSpeed);
- }
-
- private boolean nearDoor(code_swarm.Node node) {
- if (node.mPosition.x > (midWayX - doorWayLeft) && node.mPosition.x < (midWayX + doorWayRight)) {
- if (node.mPosition.y >= startDoorY && node.mPosition.y <= midWayY) {
- return true;
- }
- }
- return false;
- }
-
- private void constrainNode(code_swarm.Node node, boolean rightSide) {
- if (nearDoor(node)) {
- if (doorOpen) {
- node.mPosition.set(constrain(node.mPosition.x, 0.0f, (float)code_swarm.width),constrain(node.mPosition.y, 0.0f, (float)code_swarm.height));
- } else {
- if (rightSide) {
- node.mPosition.set(constrain(node.mPosition.x, (float)(midWayX + 8), (float)code_swarm.width),constrain(node.mPosition.y, 0.0f, (float)code_swarm.height));
- } else {
- node.mPosition.set(constrain(node.mPosition.x, 0.0f, (float)(midWayX - 8)),constrain(node.mPosition.y, 0.0f, (float)code_swarm.height));
- }
- }
- } else { // not near the door.
- if (rightSide) {
- node.mPosition.set(constrain(node.mPosition.x, (float)(midWayX + 8), (float)code_swarm.width),constrain(node.mPosition.y, 0.0f, (float)code_swarm.height));
- } else {
- node.mPosition.set(constrain(node.mPosition.x, 0.0f, (float)(midWayX - 8)),constrain(node.mPosition.y, 0.0f, (float)code_swarm.height));
- }
- }
- }
-
- private boolean whichSide(code_swarm.Node node) {
- // which half of the screen are we on?
- // true = right side
- return (node.mPosition.x >= midWayX);
- }
-
- /**
- * Interface methods below.
- */
-
- /**
- * draw the wall opened or closed, depending on closeness of people.
- */
- public void initializeFrame() {
- doorOpen = false;
-
- for (code_swarm.PersonNode p : code_swarm.getLivingPeople()) {
- if (p.mSpeed.x < 0.0f && nearDoor(p)) {
- doorOpen = true;
- break;
- }
- }
-
- drawWall();
- }
-
-
- /**
- * Method that allows Physics Engine to modify forces between files and people during the relax stage
- *
- * @param edge the edge to which the force apply (both ends)
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.Edge edge) {
- boolean fSide = whichSide(edge.nodeFrom);
- boolean pSide = whichSide(edge.nodeTo);
-
- if ((!doorOpen && fSide != pSide) || ((doorOpen && edge.nodeFrom.mPosition.y < startDoorY) || (doorOpen && edge.nodeFrom.mPosition.y > startDoorY + doorSize))) {
- return;
- }
-
- // Calculate force between the node "from" and the node "to"
- Vector2f force = calculateForceAlongAnEdge(edge);
-
- // transmit force projection to file and person nodes
- force.negate();
- applyForceTo(edge.nodeFrom, force); // fNode: attract fNode to pNode
- // which half of the screen are we on?
- applySpeedTo(edge.nodeFrom); // fNode: move it.
- constrainNode(edge.nodeFrom, whichSide(edge.nodeFrom)); // Keep it in bounds.
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param fNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.FileNode fNode ) {
- boolean mySide = whichSide(fNode);
-
- Vector2f forceBetweenFiles = new Vector2f();
- Vector2f forceSummation = new Vector2f();
-
- // Calculation of repulsive force between persons
- for (code_swarm.FileNode n : code_swarm.getLivingNodes()) {
- if (n != fNode && mySide == whichSide(n)) {
- // elemental force calculation, and summation
- forceBetweenFiles = calculateForceBetweenfNodes(fNode, n);
- forceSummation.add(forceBetweenFiles);
- }
- }
- // Apply repulsive force from other files to this Node
- applyForceTo(fNode, forceSummation);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the update phase.
- *
- * @param fNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onUpdate(code_swarm.FileNode fNode) {
- // Apply Speed to Position on nodes
- applySpeedTo(fNode);
- constrainNode(fNode, whichSide(fNode)); // Keep it in bounds.
-
- // shortening life
- fNode.decay();
-
- // Apply drag (reduce Speed for next frame calculation)
- fNode.mSpeed.scale(DRAG);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param pNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.PersonNode pNode) {
- if (pNode.mSpeed.length() == 0) {
- // Range (-1,1)
- pNode.mSpeed.set(pNode.mass*((float)Math.random()-pNode.mass),pNode.mass*((float)Math.random()-pNode.mass));
- }
-
- pNode.mSpeed.scale(pNode.mass);
- pNode.mSpeed.normalize();
- pNode.mSpeed.scale(5);
-
- float distance = pNode.mSpeed.length();
- if (distance > 0) {
- float deltaDistance = (pNode.mass - distance) / (distance * 2);
- deltaDistance *= ((float)pNode.life / pNode.LIFE_INIT);
-
- pNode.mSpeed.scale(deltaDistance);
- }
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the update phase.
- *
- * @param pNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onUpdate(code_swarm.PersonNode pNode) {
- boolean rightSide = whichSide(pNode);
-
- applySpeedTo(pNode);
-
- // Check for collisions with neighbors.
- for (code_swarm.PersonNode p : code_swarm.getLivingPeople()) {
- if (pNode != p) {
- Vector2f force = calculateForceBetweenpNodes(pNode,p);
- pNode.mPosition.add(force);
- }
- }
-
- constrainNode(pNode, rightSide); // Keep it in bounds.
-
- if (doorOpen) {
- // Check for vertical wall collisions
- // 4 walls to check.
- // | | |
- // | | |
- // | |
- // | | |
- // | | |
- if (pNode.mPosition.y < startDoorY || pNode.mPosition.y > midWayY) { // Above the door, and below the door.
- if (rightSide) {
- if ((pNode.mPosition.x < (midWayX + pNode.mass) && pNode.mSpeed.x < 0.0f) || (pNode.mPosition.x > (code_swarm.width - pNode.mass) && pNode.mSpeed.x > 0.0f)) {
- pNode.mSpeed.x = -pNode.mSpeed.x;
- int i = 0;
- while (pNode.mPosition.x < (midWayX + pNode.mass) || pNode.mPosition.x > (code_swarm.width - pNode.mass)) {
- pNode.mPosition.x += pNode.mSpeed.x * (i++ % 10);
- }
- }
- } else { // left side
- if ((pNode.mPosition.x < pNode.mass && pNode.mSpeed.x < 0.0f) || (pNode.mPosition.x > (midWayX - pNode.mass) && pNode.mSpeed.x > 0.0f)) {
- pNode.mSpeed.x = -pNode.mSpeed.x;
- int i = 0;
- while (pNode.mPosition.x < pNode.mass || pNode.mPosition.x > (midWayX - pNode.mass)) {
- pNode.mPosition.x += pNode.mSpeed.x * (i++ % 10);
- }
- }
- }
- } else { // Same level as the door
- if ((pNode.mPosition.x < pNode.mass && pNode.mSpeed.x < 0.0f) || (pNode.mPosition.x > (code_swarm.width - pNode.mass) && pNode.mSpeed.x > 0.0f)) {
- pNode.mSpeed.x = -pNode.mSpeed.x;
- int i = 0;
- while (pNode.mPosition.x < pNode.mass || pNode.mPosition.x > (code_swarm.width - pNode.mass)) {
- pNode.mPosition.x += pNode.mSpeed.x * (i++ % 10);
- }
- }
- }
- } else { // Door is closed.
- // Check for vertical wall collisions
- // 3 walls to check.
- // | | |
- // | | |
- // | | |
- // | | |
- // | | |
-
- if (rightSide) {
- if ((pNode.mPosition.x < (midWayX + pNode.mass) && pNode.mSpeed.x < 0.0f) || (pNode.mPosition.x > (code_swarm.width - pNode.mass) && pNode.mSpeed.x > 0.0f)) {
- pNode.mSpeed.x = -pNode.mSpeed.x;
- int i = 0;
- while (pNode.mPosition.x < (midWayX + pNode.mass) || pNode.mPosition.x > (code_swarm.width - pNode.mass)) {
- pNode.mPosition.x += pNode.mSpeed.x * (i++ % 10);
- }
- }
- } else { // left side
- if ((pNode.mPosition.x < pNode.mass && pNode.mSpeed.x < 0.0f) || (pNode.mPosition.x > (midWayX - pNode.mass) && pNode.mSpeed.x > 0.0f)) {
- pNode.mSpeed.x = -pNode.mSpeed.x;
- int i = 0;
- while (pNode.mPosition.x < pNode.mass || pNode.mPosition.x > (midWayX - pNode.mass)) {
- pNode.mPosition.x += pNode.mSpeed.x * (i++ % 10);
- }
- }
- }
- }
-
- // Check for horizontal wall collisions
- // 2 walls to check.
- // _______
- //
- //
- //
- // _______
-
- if ((pNode.mPosition.y < pNode.mass && pNode.mSpeed.y < 0.0f) || ((pNode.mPosition.y > (code_swarm.height - pNode.mass) && pNode.mSpeed.y > 0.0f))) {
- pNode.mSpeed.y = -pNode.mSpeed.y;
- int i = 0;
- while (pNode.mPosition.y < pNode.mass || pNode.mPosition.y > (code_swarm.height - pNode.mass)) {
- pNode.mPosition.y += pNode.mSpeed.y * (i++ % 10);
- }
- }
- // shortening life
- pNode.decay();
-
- // Apply drag (reduce Speed for next frame calculation)
- pNode.mSpeed.scale(DRAG);
- }
-
- /**
- *
- * @return Vector2f vector holding the starting location for a Person Node
- */
- public Vector2f pStartLocation() {
- float x = (float)Math.random() * midWayX + midWayX;
- float y = (float)Math.random() * code_swarm.height;
-
- constrain(x, (midWayX + 10), (code_swarm.width - 10));
- constrain(y, 10, (code_swarm.height - 10));
-
- Vector2f vec = new Vector2f(x, y);
-
- return vec;
- }
-
- /**
- *
- * @return Vector2f vector holding the starting location for a File Node
- */
- public Vector2f fStartLocation() {
- float x = (float)Math.random() * midWayX + midWayX;
- float y = (float)Math.random() * code_swarm.height;
-
- constrain(x, (midWayX + 10), (code_swarm.width - 10));
- constrain(y, 10, (code_swarm.height - 10));
-
- Vector2f vec = new Vector2f(x, y);
-
- return vec;
- }
-
-}
-
View
199 src/PhysicsEngineSimple.java
@@ -1,199 +0,0 @@
-/**
- * Copyright 2008 code_swarm project team
- *
- * This file is part of code_swarm.
- *
- * code_swarm is free software: you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation, either version 3 of the License, or
- * (at your option) any later version.
- *
- * code_swarm 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
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with code_swarm. If not, see <http://www.gnu.org/licenses/>.
- */
-
-import javax.vecmath.Vector2f;
-
-
-/**
- * @brief Simple algorithms describing all physicals interactions between nodes (files and persons)
- *
- * This is a free test to explore dans demonstrate PhysicalEngine designs.
- *
- * @see PhysicsEngine Physics Engine Interface
- */
-public class PhysicsEngineSimple extends PhysicsEngine
-{
- private CodeSwarmConfig cfg;
-
- private float FORCE_EDGE_MULTIPLIER;
- private float FORCE_NODES_MULTIPLIER;
- private float FORCE_TO_SPEED_MULTIPLIER;
-
- /**
- * Method for initializing parameters.
- * @param p Properties from the config file.
- */
- //PhysicalEngineSimple(float forceEdgeMultiplier, float forceToSpeedMultiplier, float speedToPositionDrag)
- public void setup (CodeSwarmConfig p)
- {
- cfg = p;
- FORCE_EDGE_MULTIPLIER = cfg.getFloatProperty("edgeMultiplier",1.0);
- FORCE_NODES_MULTIPLIER = cfg.getFloatProperty("nodesMultiplier",1.0);
- FORCE_TO_SPEED_MULTIPLIER = cfg.getFloatProperty("speedMultiplier",1.0);
- SPEED_TO_POSITION_MULTIPLIER = cfg.getFloatProperty("drag",0.5);
- }
-
- /**
- * Simple method that calculate the attractive/repulsive force between a person and one of its file along their link (the edge).
- *
- * @param edge the link between a person and one of its file
- * @return force force calculated between those two nodes
- */
- private Vector2f calculateForceAlongAnEdge( code_swarm.Edge edge )
- {
- float distance;
- float deltaDistance;
- Vector2f force = new Vector2f();
- Vector2f tforce = new Vector2f();
-
- // distance calculation
- tforce.sub( edge.nodeTo.mPosition, edge.nodeFrom.mPosition);
- distance = tforce.length();
- // force calculation (increase when distance is different from targeted len)
- deltaDistance = (edge.len - distance);
- // force projection onto x and y axis
- tforce.scale( deltaDistance * FORCE_EDGE_MULTIPLIER );
- force.set(tforce);
-
- return force;
- }
-
- /**
- * Simple method that calculate the repulsive force between two similar nodes (either files or persons).
- *
- * @param nodeA [in]
- * @param nodeB [in]
- * @return force force calculated between those two nodes
- */
- private Vector2f calculateForceBetweenNodes( code_swarm.Node nodeA, code_swarm.Node nodeB )
- {
- float distance;
- Vector2f force = new Vector2f();
- Vector2f normVec = new Vector2f();
-
- /**
- * Get the distance between nodeA and nodeB
- */
- normVec.sub(nodeA.mPosition, nodeB.mPosition);
- distance = normVec.length();
- if (distance > 0) {
- // No collision
- normVec.scale(1/distance * FORCE_NODES_MULTIPLIER);
- force.set(normVec);
- }
-
- return force;
- }
-
- /**
- * Simple method that apply a force to a node, converting acceleration to speed.
- *
- * @param node [in] Node the node to which the force apply
- * @param force [in] force a force Vector representing the force on a node
- *
- * TODO: does force should be a property of the node (or not?)
- */
- private void applyForceTo( code_swarm.Node node, Vector2f force )
- {
- float dlen;
- Vector2f mod = new Vector2f();
-
- /** TODO: add comment to this algorithm */
- dlen = force.length();
- if ( (dlen > 0) && (node.mass > 0)) {
- mod.set(((force.x / (node.mass / dlen)) * FORCE_TO_SPEED_MULTIPLIER),
- ((force.y / (node.mass / dlen)) * FORCE_TO_SPEED_MULTIPLIER));
- node.mSpeed.add(mod);
- }
- }
-
-
-
- /**
- * Method that allows Physics Engine to modify forces between files and people during the relax stage
- *
- * @param edge the edge to which the force apply (both ends)
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.Edge edge) {
- Vector2f force = new Vector2f();
-
- // Calculate force between the node "from" and the node "to"
- force = calculateForceAlongAnEdge(edge);
-
- // transmit (applying) fake force projection to file and person nodes
- applyForceTo(edge.nodeTo, force);
- force.negate(); // force is inverted for the other end of the edge
- applyForceTo(edge.nodeFrom, force);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param fNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.FileNode fNode ) {
- Vector2f forceBetweenFiles = new Vector2f();
- Vector2f forceSummation = new Vector2f();
-
- // Calculation of repulsive force between persons
- for (code_swarm.FileNode n : code_swarm.getLivingNodes()) {
- if (n != fNode) {
- // elemental force calculation, and summation
- forceBetweenFiles = calculateForceBetweenNodes(fNode, n);
- forceSummation.add(forceBetweenFiles);
- }
- }
- // Apply repulsive force from other files to this Node
- applyForceTo(fNode, forceSummation);
- }
-
- /**
- * Method that allows Physics Engine to modify Speed / Position during the relax phase.
- *
- * @param pNode the node to which the force apply
- *
- * @Note Standard physics is "Position Variation = Speed x Duration" with a convention of "Duration=1" between to frames
- */
- public void onRelax(code_swarm.PersonNode pNode) {
- Vector2f forceBetweenPersons = new Vector2f();
- Vector2f forceSummation = new Vector2f();
-
- // Calculation of repulsive force between persons
- for (code_swarm.PersonNode p : code_swarm.getLivingPeople()) {
- if (p != pNode) {
- // elemental force calculation, and summation
- forceBetweenPersons = calculateForceBetweenNodes(pNode, p);
- forceSummation.add(forceBetweenPersons);
- }
- }
-
- // Apply repulsive force from other persons to this Node
- applyForceTo(pNode, forceSummation);
- }
-
-
-
-
-
-}
-

0 comments on commit 6afad8b

Please sign in to comment.