Skip to content

Commit

Permalink
Changes to the clustering algorithm and a little clean up w/ textures.
Browse files Browse the repository at this point in the history
  • Loading branch information
Robert Knapp committed Sep 10, 2011
1 parent 123e080 commit da4a6df
Show file tree
Hide file tree
Showing 4 changed files with 211 additions and 97 deletions.
7 changes: 5 additions & 2 deletions build_cluster.py
Expand Up @@ -25,7 +25,7 @@
import random

class ModelBase():
def __init__(self, panda, nodes, radius = 5, center = None):
def __init__(self, panda, nodes, radius = 5, center = None, scale = None):
self.panda = panda
self.nodes = {}
self.slugs = {}
Expand All @@ -36,6 +36,7 @@ def __init__(self, panda, nodes, radius = 5, center = None):
else:
self.center = center
self._radius = radius
self.scale = scale
self.draw_nodes(nodes)

def draw_nodes(self, number_of_nodes):
Expand All @@ -53,7 +54,9 @@ def draw_nodes(self, number_of_nodes):
#degrees = degrees + step
#radians = degrees * (pi / 180)
self.nodes[i] = self.panda.loader.loadModel("models/crt.egg")
self.nodes[i].reparentTo(render)
if self.scale:
self.nodes[i].setScale(self.scale)
self.nodes[i].reparentTo(self.center)
self.nodes[i].setPos(self._radius * (cos(phi)*r), self._radius*y, self._radius * (sin(phi)*r))

self.nodes[i].setColorScale(0.5, 0.41, 0.80, 1)
Expand Down
45 changes: 24 additions & 21 deletions physics/__init__.py
@@ -1,7 +1,7 @@
from pandac.PandaModules import OdeBody, OdeMass, ActorNode, Vec3, ForceNode, LinearVectorForce, NodePath


MAX_FORCE = 10000
MAX_FORCE = 100000
class Spring(object):

def __init__(self, base, render, node1, node2, nodeMass=1, springConstant = 1, drag=5, actor1=None, actor2=None, lengthFactor =1):
Expand Down Expand Up @@ -71,25 +71,28 @@ def timer(self, task):


if force:
forceVector = self._node1.getPos() - self._node2.getPos()
self._force1 = ForceNode('force1')
self._node1.attachNewNode(self._force1)
force2 = self._node2.getRelativeVector( self._node1, force)
lvf1 = LinearVectorForce(force.x , force.y, force.z)
#print force
self._force1.addForce( lvf1 )
lvf1.setMassDependent(1)
self._force2 = ForceNode('force2')
self._node2.attachNewNode(self._force2)
lvf2 = LinearVectorForce( LinearVectorForce( Vec3( -1* force2.x, -1 * force2.y, -1* force2.z)))
lvf2.setMassDependent(1)
self._force2.addForce(lvf2)
#self._base.physicsMgr.addLinearForce(lvf1)
#self._base.physicsMgr.addLinearForce(lvf2)
self._actor1.getPhysical(0).addLinearForce(lvf1)
self._actor2.getPhysical(0).addLinearForce(lvf2)
self._force1 = lvf1
self._force2 = lvf2
try:
forceVector = self._node1.getPos() - self._node2.getPos()
self._force1 = ForceNode('force1')
self._node1.attachNewNode(self._force1)
force2 = self._node2.getRelativeVector( self._node1, force)
lvf1 = LinearVectorForce(force.x , force.y, force.z)
#print force
self._force1.addForce( lvf1 )
lvf1.setMassDependent(1)
self._force2 = ForceNode('force2')
self._node2.attachNewNode(self._force2)
lvf2 = LinearVectorForce( LinearVectorForce( Vec3( -1* force2.x, -1 * force2.y, -1* force2.z)))
lvf2.setMassDependent(1)
self._force2.addForce(lvf2)
#self._base.physicsMgr.addLinearForce(lvf1)
#self._base.physicsMgr.addLinearForce(lvf2)
self._actor1.getPhysical(0).addLinearForce(lvf1)
self._actor2.getPhysical(0).addLinearForce(lvf2)
self._force1 = lvf1
self._force2 = lvf2
except:
traceback.print_exc()
return task.cont
def getForce(self):

Expand Down Expand Up @@ -121,7 +124,7 @@ def getForce(self):
#print "Spring force " + str(force)
#self.lastTime = newTime
#print "Combined " + str(force)
if force.length()>.01 and force.length() < MAX_FORCE:
if force.length()>.0005 and force.length() < MAX_FORCE:
return force
elif force.length() >MAX_FORCE:
#we max all big forces out at 500 otherwise bad things can happen if chaos ensuse.
Expand Down

0 comments on commit da4a6df

Please sign in to comment.