Exemplo n.º 1
0
void Bone_api(const mxArray * const prhs[4], const mxArray *plhs[1])
{
  real_T (*vals)[2];
  emxArray_real_T *spacePoints;
  emxArray_real_T *timePoints;
  real_T k;
  real_T t;
  emlrtStack st = { NULL, NULL, NULL };

  st.tls = emlrtRootTLSGlobal;
  vals = (real_T (*)[2])mxMalloc(sizeof(real_T [2]));
  emlrtHeapReferenceStackEnterFcnR2012b(&st);
  emxInit_real_T(&st, &spacePoints, 2, &ub_emlrtRTEI, true);
  emxInit_real_T(&st, &timePoints, 2, &ub_emlrtRTEI, true);

  /* Marshall function inputs */
  k = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[0]), "k");
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[1]), "spacePoints", spacePoints);
  t = c_emlrt_marshallIn(&st, emlrtAliasP(prhs[2]), "t");
  e_emlrt_marshallIn(&st, emlrtAlias(prhs[3]), "timePoints", timePoints);

  /* Invoke the target function */
  Bone(&st, k, spacePoints, t, timePoints, *vals);

  /* Marshall function outputs */
  plhs[0] = c_emlrt_marshallOut(*vals);
  timePoints->canFreeData = false;
  emxFree_real_T(&timePoints);
  spacePoints->canFreeData = false;
  emxFree_real_T(&spacePoints);
  emlrtHeapReferenceStackLeaveFcnR2012b(&st);
}
Exemplo n.º 2
0
Bone* SceneAnimator::loadSkeleton(ByteBuffer& dataIn, Bone* parent) {
    stringImpl tempString;
    // create a node
    Bone* internalNode = MemoryManager_NEW Bone();
    // set the parent, in the case this is the root node, it will be null
    internalNode->_parent = parent;  
    // the name of the bone
    dataIn >> tempString;
    internalNode->name(tempString);
    // the bone offsets
    dataIn >> internalNode->_offsetMatrix;
    // original bind pose
    dataIn >> internalNode->_originalLocalTransform;
 
    // a copy saved
    internalNode->_localTransform = internalNode->_originalLocalTransform;
    calculateBoneToWorldTransform(internalNode);
    // the number of children
    U32 nsize = 0;
    dataIn >> nsize;

    // recursively call this function on all children
    // continue for all child nodes and assign the created internal nodes as our children
    for (U32 a = 0; a < nsize; a++) {
        internalNode->_children.push_back(loadSkeleton(dataIn, internalNode));
    }
    return internalNode;
}
Exemplo n.º 3
0
 //---------------------------------------------------------------------
 Bone* Skeleton::createBone(const String& name, unsigned short handle)
 {
     if (handle >= OGRE_MAX_NUM_BONES)
     {
         OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Exceeded the maximum number of bones per skeleton.",
             "Skeleton::createBone");
     }
     // Check handle not used
     if (handle < mBoneList.size() && mBoneList[handle] != NULL)
     {
         OGRE_EXCEPT(
             Exception::ERR_DUPLICATE_ITEM,
             "A bone with the handle " + StringConverter::toString(handle) + " already exists",
             "Skeleton::createBone" );
     }
     // Check name not used
     if (mBoneListByName.find(name) != mBoneListByName.end())
     {
         OGRE_EXCEPT(
             Exception::ERR_DUPLICATE_ITEM,
             "A bone with the name " + name + " already exists",
             "Skeleton::createBone" );
     }
     Bone* ret = OGRE_NEW Bone(name, handle, this);
     if (mBoneList.size() <= handle)
     {
         mBoneList.resize(handle+1);
     }
     mBoneList[handle] = ret;
     mBoneListByName[name] = ret;
     return ret;
 }
Exemplo n.º 4
0
Board::Board() //Constructor for the Board class
{
	spinner = Bone();
	rightRow.reserve(28);
	leftRow.reserve(27);
	topRow.reserve(25);
	bottomRow.reserve(25);
}
Exemplo n.º 5
0
Arquivo: as4.cpp Projeto: cgtz/ik
//****************************************************
// the usual stuff, nothing exciting here
//****************************************************
int main(int argc, char *argv[]) {
    if (argc > 1) {
        octopus = 1;
    }
    if (octopus) {
        for (int i = 0; i<8; i++) {
            std::vector<Bone> arm;
            for (int j=0; j<10; j++) {
                arm.push_back(Bone(0.3f));
            }
            appendages.push_back(arm);
            goals.push_back(coolShapes[shape](0));
        }
    } else {
        for (int i = 0; i<1; i++) {
            std::vector<Bone> arm;
            arm.push_back(Bone(2.0f));
            arm.push_back(Bone(1.0f));
            arm.push_back(Bone(1.3f));
            arm.push_back(Bone(0.5f));
            arm.push_back(Bone(0.8f));
            arm.push_back(Bone(0.3f));
            arm.push_back(Bone(1.0f));
            appendages.push_back(arm);
            goals.push_back(coolShapes[shape](0));
        }
    }

    //This initializes glut
	glutInit(&argc, argv);

	//This tells glut to use a double-buffered window with red, green, and blue channels 
	glutInitDisplayMode(GLUT_DOUBLE | GLUT_RGBA | GLUT_DEPTH);

	// Initalize theviewport size
	viewport.w = 640;
	viewport.h = 480;

	//The size and position of the window
	glutInitWindowSize(viewport.w, viewport.h);
	glutInitWindowPosition(0,0);
	glutCreateWindow(argv[0]);

	initScene();							// quick function to set up scene

	glutDisplayFunc(myDisplay);				// function to run when its time to draw something
    glutIdleFunc(myIdle);
	glutReshapeFunc(myReshape);				// function to run when the window gets resized
	glutKeyboardFunc(keyboard);
	glutSpecialFunc(arrows);
	glutMainLoop();							// infinite loop that will keep drawing and resizing

	return 0;
}
Exemplo n.º 6
0
void Renderer6::GenerateBoneData()
{
    // Create surface
    m_chain = new BoneChain();
    m_chain->AddBone(Bone(vec3(0.707f, 0.707f, 0.0f)));
    m_chain->AddBone(Bone(vec3(0.707f, -0.707f, 0.0f)));
    m_chain->AddBone(Bone(vec3(-0.707f, -0.707f, 0.0f)));
    m_chain->AddBone(Bone(vec3(1.0f, 0.0f, 0.0f)));
    m_chain->AddBone(Bone(vec3(0.707f, -0.707f, 0.0f)));
    
    ComputeMatrices(m_matrices);
    
    vector<float> boneData = m_chain->GetVertexData();
    
    // Generate bone vertex buffer
    glGenBuffers(1, &m_boneVertexBuffer);
    glBindBuffer(GL_ARRAY_BUFFER, m_boneVertexBuffer);
    glBufferData(GL_ARRAY_BUFFER, sizeof(float) * boneData.size(), &boneData[0], GL_STATIC_DRAW);
}
Skeleton app::skeletonOSCMessageToSkeleton(ofxOscMessage * msg)
{
	//If this message is not formatted correctly
	if(msg->getNumArgs() !=numSkeletonOSCArgs)
	{
		cout << "Skeleton OSC message does not have " << numSkeletonOSCArgs << " args as required... - has " <<  msg->getNumArgs() << endl;
	}

	//This is tied directly to the order of information within the packet
	Skeleton s;
	// 0 - bundle index, not used here
	// 1 - skeleton index
	s.idx = msg->getArgAsInt32(1);
	// 2-HandLeftx
	// 3-HandLefty
	Joint handleft = Joint(ofPoint(msg->getArgAsFloat(2),msg->getArgAsFloat(3)), Joint::Type_HandLeft);
	// 4-WristLeftx
	// 5-WristLefty
	Joint wristleft = Joint(ofPoint(msg->getArgAsFloat(4),msg->getArgAsFloat(5)), Joint::Type_WristLeft);
	// 6-ElbowLeftx
	// 7-ElbowLefty
	Joint elbowleft = Joint(ofPoint(msg->getArgAsFloat(6),msg->getArgAsFloat(7)), Joint::Type_ElbowLeft);
	// 8-ElbowRightx
	// 9-ElbowRighty
	Joint elbowright = Joint(ofPoint(msg->getArgAsFloat(8),msg->getArgAsFloat(9)), Joint::Type_ElbowRight);
	// 10-WristRightx
	// 11-WristRight7
	Joint wristright = Joint(ofPoint(msg->getArgAsFloat(10),msg->getArgAsFloat(11)), Joint::Type_WristRight);
	// 12-HandRightx
	// 13-HandRighty
	Joint handright = Joint(ofPoint(msg->getArgAsFloat(12),msg->getArgAsFloat(13)), Joint::Type_HandRight);
	// 14-ShoulderLeftx
	// 15-ShoulderLefty
	Joint shoulderleft = Joint(ofPoint(msg->getArgAsFloat(14),msg->getArgAsFloat(15)), Joint::Type_ShoulderLeft);
	// 16-ShoulderRightx
	// 17-ShoulderRight7
	Joint shoulderright = Joint(ofPoint(msg->getArgAsFloat(16),msg->getArgAsFloat(17)), Joint::Type_ShoulderRight);
	// 18 - kinect id
	s.src_kinect = msg->getArgAsInt32(18);

	//Now construct the list of bones
	//Hand->wrist
	s.bones.push_back(Bone(handleft,wristleft));
	s.bones.push_back(Bone(handright,wristright));
	//Wrist->Elbow
	s.bones.push_back(Bone(wristleft,elbowleft));
	s.bones.push_back(Bone(wristright,elbowright));
	//Elbow->Shoulder
	s.bones.push_back(Bone(elbowleft,shoulderleft));
	s.bones.push_back(Bone(elbowright,shoulderright));
	//Shoulders
	s.bones.push_back(Bone(shoulderleft,shoulderright));

	return s;
}
Exemplo n.º 8
0
//==============================================================================
void Skeleton::load(const CString& filename, ResourceInitializer& init)
{
	XmlDocument doc;
	doc.loadFile(filename, init.m_tempAlloc);

	XmlElement rootEl = doc.getChildElement("skeleton");
	XmlElement bonesEl = rootEl.getChildElement("bones");

	// count the bones count
	U bonesCount = 0;

	XmlElement boneEl = bonesEl.getChildElement("bone");

	do
	{
		++bonesCount;
		boneEl = boneEl.getNextSiblingElement("bone");
	} while(boneEl);

	// Alloc the vector
	m_bones = std::move(ResourceVector<Bone>(init.m_alloc));
	m_bones.resize(bonesCount, Bone(init.m_alloc));

	// Load every bone
	boneEl = bonesEl.getChildElement("bone");
	bonesCount = 0;
	do
	{
		Bone& bone = m_bones[bonesCount++];

		// <name>
		XmlElement nameEl = boneEl.getChildElement("name");
		bone.m_name = nameEl.getText();

		// <transform>
		XmlElement trfEl = boneEl.getChildElement("transform");
		bone.m_transform = trfEl.getMat4();

		// Advance 
		boneEl = boneEl.getNextSiblingElement("bone");
	} while(boneEl);
}
Exemplo n.º 9
0
unsigned int Board::getLastValueByRow(char row) //Gets the value of the last bone on the row
{
	vector<Bone> vecRow = getRow(row);
	Bone lastBone;
	if (vecRow.size() == 0)
		if (toupper(row) == 'W' && !hasSpinner())
		{
			lastBone = rightRow[0];
			if (rightRow.size() == 1)
				lastBone.swap();
		}
		else if (!hasSpinner())
			lastBone = Bone();
		else
			lastBone = *getSpinner();
	else
		lastBone = vecRow[vecRow.size() - 1];
	if (toupper(row) == 'E' && !hasSpinner() && vecRow.size() == 1)
		return lastBone.getValue1();
	else
		return lastBone.getValue2();
}
Exemplo n.º 10
0
bool
id::FBX::Model::initBone(FbxNode* node, int parentIndex)
{
	FbxSkeleton*	bone = node->GetSkeleton();
	size_t			myBone;

	if (bone != nullptr)
	{
		try
		{
			_bones.push_back(Bone());
		}
		catch (std::bad_alloc b)
		{
			b.what();
			return false;
		}
		myBone = _bones.size() - 1;
		_bones[myBone].parentIndex = parentIndex;
		_bones[myBone].node = node;
	}
	return true;
}
Exemplo n.º 11
0
BoneSprite::BoneSprite() {
    base.tex="testb";
    base.sx=5;
    base.sy=10;
    offset=9;

    Joint *urleg,*lrleg,*ulleg,*llleg;
    urleg=new Joint(Bone("testb",1,5),1);
    lrleg=new Joint(Bone("testb",1,5),1);
    ulleg=new Joint(Bone("testb",1,5),1);
    llleg=new Joint(Bone("testb",1,5),1);

    ulleg->tx=urleg->tx=.5;
    ulleg->ty=urleg->ty=4.5;
    ulleg->bx=urleg->bx=2.5;
    ulleg->by=urleg->by=0;

    llleg->tx=lrleg->tx=.5;
    llleg->ty=lrleg->ty=4.5;
    llleg->bx=lrleg->bx=.5;
    llleg->by=lrleg->by=.5;

    base.joints.push_back(ulleg);
    base.joints.push_back(urleg);
    ulleg->bone.joints.push_back(llleg);
    urleg->bone.joints.push_back(lrleg);

    Joint *ufarm,*lfarm,*ubarm,*lbarm;
    ufarm=new Joint(Bone("testb",1,5),1);
    ubarm=new Joint(Bone("testb",1,5),1);
    lfarm=new Joint(Bone("testb",1,5),1);
    lbarm=new Joint(Bone("testb",1,5),1);

    ubarm->tx=ufarm->tx=.5;
    ubarm->ty=ufarm->ty=4.5;
    ubarm->bx=ufarm->bx=2.5;
    ubarm->by=ufarm->by=8;

    lbarm->tx=lfarm->tx=.5;
    lbarm->ty=lfarm->ty=4.5;
    lbarm->bx=lfarm->bx=.5;
    lbarm->by=lfarm->by=.5;

    base.joints.push_back(ufarm);
    base.joints.push_back(ubarm);
    ufarm->bone.joints.push_back(lfarm);
    ubarm->bone.joints.push_back(lbarm);

	//idle
    urleg->pre.push_back(new StaticPredictor(0));
    lrleg->pre.push_back(new StaticPredictor(0));
    ulleg->pre.push_back(new StaticPredictor(0));
    llleg->pre.push_back(new StaticPredictor(0));
    ufarm->pre.push_back(new StaticPredictor(0));
    ubarm->pre.push_back(new StaticPredictor(0));
    lfarm->pre.push_back(new StaticPredictor(3.14159/2));
    lbarm->pre.push_back(new StaticPredictor(3.14159/2));

	//walk
    urleg->pre.push_back(new MinMaxPredictor(-.5,.5,.2,0));
    lrleg->pre.push_back(new HalfPredictor(urleg->pre[1]));
    ulleg->pre.push_back(new MirrorPredictor(urleg->pre[1]));
    llleg->pre.push_back(new HalfPredictor(ulleg->pre[1]));
    ufarm->pre.push_back(new MinMaxPredictor(-.5,.5,.1,0));
    ubarm->pre.push_back(new MirrorPredictor(ufarm->pre[1]));
    lfarm->pre.push_back(new StaticPredictor(3.14159/2));
    lbarm->pre.push_back(new StaticPredictor(3.14159/2));


}
Exemplo n.º 12
0
		Bone* Skeleton::CreateBone(const char* name)
		{
			Bone* bone = NULL;

			//Insert into map
			std::pair<std::map<std::string, Bone>::iterator, bool> result = mBones.insert(std::pair<std::string, Bone>(name, Bone(name)));

			if(result.second)
			{
				bone = &(*result.first).second;
			}

			return bone;
		}
Exemplo n.º 13
0
 Bone Bone::clone(){
     return Bone(*this);
 }
void copyAiMeshBones(const aiMesh *sourceMesh, AnimatedMesh &mesh)
{
    //Copy bones.
    std::vector<unsigned int> vertexBoneCounts(mesh.vertices.size(), 0);
    
    mesh.skeleton.bones.resize(sourceMesh->mNumBones);
    
    for (unsigned int i = 0; i < mesh.skeleton.bones.size(); ++i)
    {
        const aiBone *sourceBone = sourceMesh->mBones[i];
        
        mesh.skeleton.bones[i] = Bone(std::string(sourceBone->mName.data),
                                      aiMatrixToMat4(sourceBone->mOffsetMatrix));
        
        //Retrieve weights for vertices affected by this bone.
        for (unsigned int j = 0; j < sourceBone->mNumWeights; ++j)
        {
            const unsigned int id = sourceBone->mWeights[j].mVertexId;
            const float weight = sourceBone->mWeights[j].mWeight;
            
            if (id >= mesh.vertices.size() || weight < 0.0f || weight > 1.0f)
            {
                std::cerr << "Mesh has invalid bone indices " << id << " or weights " << weight << "!" << std::endl;
                throw std::exception();
            }
            
            //Discard small weights.
            if (weight <= 0.001f)
            {
                continue;
            }
            
            const unsigned int count = vertexBoneCounts[id];
            
            if (count >= 4)
            {
                std::cerr << "Warning: mesh contains more than four bones per vertex, discarding excess data!" << std::endl;
            }
            else
            {
                AnimatedMeshVertex *v = &mesh.vertices[id];
                
                if (count == 0)
                {
                    v->weights.x = weight;
                    v->bones.x = i;
                }
                else if (count == 1)
                {
                    v->weights.y = weight;
                    v->bones.y = i;
                }
                else if (count == 2)
                {
                    v->weights.z = weight;
                    v->bones.z = i;
                }
                else if (count == 3)
                {
                    v->weights.w = weight;
                    v->bones.w = i;
                }
                    
                vertexBoneCounts[id]++;
            }
        }
    }
    
#ifndef NDEBUG
    //Verify bone weights and indices.
    for (unsigned int i = 0; i < mesh.vertices.size(); ++i)
    {
        const int nrBones = mesh.skeleton.bones.size();
        const AnimatedMeshVertex v = mesh.vertices[i];
        const float weightSum = v.weights.x + v.weights.y + v.weights.z + v.weights.w;
        
        if (v.weights.x < 0.0f || v.weights.x > 1.0f ||
            v.weights.y < 0.0f || v.weights.y > 1.0f ||
            v.weights.z < 0.0f || v.weights.z > 1.0f ||
            v.weights.w < 0.0f || v.weights.w > 1.0f ||
            fabsf(weightSum - 1.0f) > 1.0e-2)
        {
            std::cerr << "Warning: invalid weights " << v.weights << " (sum " << weightSum << ")!" << std::endl;
        
            //Normalise weight sum.
            mesh.vertices[i].weights /= weightSum;
        }
        
        if ((v.bones.x < 0 || v.bones.x >= nrBones ||
             v.bones.y < 0 || v.bones.y >= nrBones ||
             v.bones.z < 0 || v.bones.z >= nrBones ||
             v.bones.w < 0 || v.bones.w >= nrBones) && nrBones > 0)
        {
            std::cerr << "Invalid bone indices " << v.bones << "!" << std::endl;
            throw std::exception();
        }
    }
#endif
}
Exemplo n.º 15
0
void load(std::vector<Bone> &bones, int bmp_w, int bmp_h, std::string filename)
{
	ALLEGRO_FILE *f;
	if (engine) {
		f = engine->get_cpa()->load(filename);
	}
	else {
		f = al_fopen(filename.c_str(), "rb");
	}

	if (!f) {
		General::log_message("Error loading bones " + filename);
		return;
	}

	char buf[1000];
	while (1) {
		if (al_fgets(f, buf, 1000) == NULL)
			break;
		Bones::Type bone_type;
		sscanf(buf, "<%d>", (int *)&bone_type);
		if (al_fgets(f, buf, 1000) == NULL)
			break;
	
		std::vector<float> vertices;

		while (1) {
			int x, y, n1, n2;
			if (al_fgets(f, buf, 1000) == NULL)
				break;
			if (sscanf(buf, "\t<%d><x>%d</x><y>%d</y></%d>", &n1, &x, &y, &n2) < 4)
				break;

			vertices.push_back(x);
			vertices.push_back(y);
		}
		
		std::vector<int> splits;
		splits.push_back(vertices.size() / 2);
		float *verts = new float[vertices.size()];
		std::vector< General::Point<float> > outline;

		for (unsigned int i = 0; i < vertices.size() / 2; i++) {
			int index = i*2;
			verts[index] = vertices[index] - bmp_w/2;
			verts[index+1] = vertices[index+1] - bmp_h;
			outline.push_back(General::Point<float>(
				verts[index], verts[index+1]
			));
		}

		std::vector<Triangulate::Triangle> triangles;

		Triangulate::get_triangles(outline, splits, triangles);

		Bone b = Bone(bone_type, outline, triangles, General::Size<int>(bmp_w, bmp_h));
		bones.push_back(b);

		delete[] verts;
	}

	al_fclose(f);
}