void ramDrawActorCube(ramNodeArray& nodeArray)
{
	if (nodeArray.getNumNode() == 0) return;

	ofVec3f maxPos = nodeArray.getNode(ramActor::JOINT_CHEST).getGlobalPosition();
	ofVec3f minPos = nodeArray.getNode(ramActor::JOINT_CHEST).getGlobalPosition();

	for (int j = 0; j < nodeArray.getNumNode(); j++)
	{
		ofVec3f pos = nodeArray.getNode(j).getGlobalPosition();

		if (maxPos.x <= pos.x) maxPos.x = pos.x;
		if (maxPos.y <= pos.y) maxPos.y = pos.y;
		if (maxPos.z <= pos.z) maxPos.z = pos.z;

		if (minPos.x > pos.x) minPos.x = pos.x;
		if (minPos.y > pos.y) minPos.y = pos.y;
		if (minPos.z > pos.z) minPos.z = pos.z;
	}

	ofVec3f scale, axis;
	scale = (maxPos - minPos);
	axis = (maxPos + minPos) / 2;

	ofPushStyle();
	ofPushMatrix();
	{
		ofTranslate(axis.x, axis.y, axis.z);
		ofScale(scale.x, scale.y, scale.z);
		ofNoFill();
		ofDrawBox(1);
	}
	ofPopMatrix();
	ofPopStyle();
}
void ramDrawNodeCorresponds(const ramNodeArray &a, const ramNodeArray &b)
{
	if (a.getNumNode() == 0) return;

	if (b.getNumNode() == 0) return;

	assert(a.getNumNode() == b.getNumNode());

	for (int i = 0; i < a.getNumNode(); i++)
	{
		ofLine(a.getNode(i).getGlobalPosition(), b.getNode(i).getGlobalPosition());
	}
}
void ramActorsScene::drawNodes(const ramNodeArray &NA)
{
	ofPushStyle();
	
	ofNoFill();
	ofSetRectMode(OF_RECTMODE_CENTER);
	
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glEnable(GL_CULL_FACE);
	
	ofColor front_color(ofGetStyle().color, 200);
	ofColor back_color(ofGetStyle().color, 150);
	
	for (int i = 0; i < NA.getNumNode(); i++)
	{
		ofSetColor(front_color);
		
		const ramNode &node = NA.getNode(i);
		const ramNode *parent = node.getParent();
		if (parent == NULL) continue;
		
		ramBox(node, 2);
		
		parent->beginTransform();
		
		ofVec3f axis(0, 0, 1);
		ofVec3f c = node.getPosition().normalized().crossed(axis);
		
		ofRotate(90, c.x, c.y, c.z);
		
		ofVec3f p0 = node.getGlobalPosition();
		ofVec3f p1 = parent->getGlobalPosition();
		
		float dist = p0.distance(p1);
		float offset = 0.2;
		
		glNormal3f(0, 0, 0);
		ofLine(ofVec3f(0), ofVec3f(0, 0, -dist));
		
		if (i < 4)
			glScalef(1., 1.8, 1);
		else if (i == 4)
			glScalef(1, 1, 3);
		else
			glScalef(1., 0.8, 1);
		
		glBegin(GL_TRIANGLE_STRIP);
		for (int n = 0; n < 6; n++)
		{
			float d = ofMap(n, 0, 5, 0, 1);
			float dd = ofMap(d, 0, 1, offset, 1 - offset);
			
			float xx = sin(d * PI) * 2 + 4;
			float zz = dd * -dist;
			float w = 5;
			
			glNormal3f(1, 0.5, 0);
			glVertex3f(xx, w, zz);
			glNormal3f(1, -0.5, 0);
			glVertex3f(xx, -w, zz);
		}
		glEnd();
		
		ofSetColor(back_color);
		
		glBegin(GL_TRIANGLE_STRIP);
		for (int n = 0; n < 6; n++)
		{
			float d = ofMap(n, 0, 5, 0, 1);
			float dd = ofMap(d, 0, 1, offset, 1 - offset);
			
			float xx = -sin(d * PI) * 1 - 6;
			float zz = dd * -dist;
			float w = 3;
			
			glNormal3f(-1, 0.5, 0);
			glVertex3f(xx, -w, zz);
			glNormal3f(-1, -0.5, 0);
			glVertex3f(xx, w, zz);
		}
		glEnd();
		
		parent->endTransform();
	}
	
	glPopAttrib();
	
	ofPopStyle();
}