Ejemplo n.º 1
0
void MainWindow::keyPressEvent(QKeyEvent* event){
    switch(event->key()){
        case Qt::Key_W:
            wPressed = true;
            break;
        case Qt::Key_A:
            aPressed = true;
            break;
        case Qt::Key_S:
            sPressed = true;
            break;
        case Qt::Key_D:
            dPressed = true;
            break;
        default:
            //Do nothing
            break;
    }
    updateMotion();
}
Ejemplo n.º 2
0
void QApplicationStatus::statusMessageReceived(const QList<QByteArray> &messageList)
{
    QByteArray topic;

    topic = messageList.at(0);
    m_rx.ParseFromArray(messageList.at(1).data(), messageList.at(1).size());

#ifdef QT_DEBUG
    std::string s;
    gpb::TextFormat::PrintToString(m_rx, &s);
    DEBUG_TAG(3, "status", "update" << topic << QString::fromStdString(s))
#endif

    if ((m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE)
            || (m_rx.type() == pb::MT_EMCSTAT_INCREMENTAL_UPDATE))
    {
        if ((topic == "motion") && m_rx.has_emc_status_motion()) {
            updateMotion(m_rx.emc_status_motion());
            if (m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE) {
                updateSync(MotionChannel);
            }
        }

        if ((topic == "config") && m_rx.has_emc_status_config()) {
            updateConfig(m_rx.emc_status_config());
            if (m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE) {
                updateSync(ConfigChannel);
            }
        }

        if ((topic == "io") && m_rx.has_emc_status_io()) {
            updateIo(m_rx.emc_status_io());
            if (m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE) {
                updateSync(IoChannel);
            }
        }

        if ((topic == "task") && m_rx.has_emc_status_task()) {
            updateTask(m_rx.emc_status_task());
            if (m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE) {
                updateSync(TaskChannel);
            }
        }

        if ((topic == "interp") && m_rx.has_emc_status_interp()) {
            updateInterp(m_rx.emc_status_interp());
            if (m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE) {
                updateSync(InterpChannel);
            }
        }

        if (m_rx.type() == pb::MT_EMCSTAT_FULL_UPDATE)
        {
            if (m_statusSocketState != Up)
            {
                m_statusSocketState = Up;
                updateState(Connected);
            }

            if (m_rx.has_pparams())
            {
                pb::ProtocolParameters pparams = m_rx.pparams();
                startStatusHeartbeat(pparams.keepalive_timer() * 2); // wait double the time of the hearbeat interval
            }
        }
        else
        {
            refreshStatusHeartbeat();
        }

        return;
    }
    else if (m_rx.type() == pb::MT_PING)
    {
        if (m_statusSocketState == Up)
        {
            refreshStatusHeartbeat();
        }
        else
        {
            updateState(Connecting);
            unsubscribe();  // clean up previous subscription
            subscribe();    // trigger a fresh subscribe
        }

        return;
    }

#ifdef QT_DEBUG
    gpb::TextFormat::PrintToString(m_rx, &s);
    DEBUG_TAG(1, "status", "update: unknown message type: " << QString::fromStdString(s))
#endif
}
Ejemplo n.º 3
0
void AM_Model::render(AMSettings *sets, ID3D10EffectTechnique *t)
{
	int finSurfaces;
	MaterialInfo *ci;
	D3DXVECTOR4 d;
	D3DXVECTOR3 s;
	D3DXVECTOR3 a;

	//update from the motion
	if (hasMotionStarted())
		updateMotion();
		
	//update all rigid bodies
	updateFromPhysics();

	//rebuild the bone matrix palette with the new bone positions
	//these are used to skin vertices in the shader
	for (int i=0;i<(int)_numBone;i++)
	{
		boneMatrixPalette2[i] = boneController.getBoneList()[i].getSkinningTrans();
	}
	palette->SetMatrixArray((float*)&(boneMatrixPalette2[0]), 0, _numBone);

	//update the world transform matrix in the shader
	world->SetMatrix((float*)&(matRotateX*matRotateY*matRotateZ*matTranslate));

	//render each material separately
	finSurfaces = 0;
	for (int i=0;i<(int)_numMaterial;i++)
	{
		ci = _material[i].getInfo();

		//get diffuse color from the material & blend with fader
		//if material is self-lit, do not apply fader
		d = D3DXVECTOR4(ci->Diffuse.R, ci->Diffuse.G, ci->Diffuse.B, 1);
		if (!alphaFade && !extendedData.getSource(i))
			d *= fader.GetCurAlphaScalar();
		d.w = ci->Alpha;
		if (alphaFade && !extendedData.getSource(i))
			d.w *= fader.GetCurAlphaScalar();
		//get ambient color from the material & blend with fader
		a = D3DXVECTOR3(ci->Ambient.R, ci->Ambient.G, ci->Ambient.B);
		if (!alphaFade && !extendedData.getSource(i))
			a *= fader.GetCurAlphaScalar();
		//get specular color from the material & blend with fader
		s = D3DXVECTOR3(ci->Specular.R, ci->Specular.G, ci->Specular.B);
		if (!alphaFade && !extendedData.getSource(i))
			s *= fader.GetCurAlphaScalar();

		if (extendedData.getSource(i))
		{
			//if the extended data says this is material is a light source
			//update the brightness coefficient in the shader
			extraBright->SetFloat(sets->getExtraBright());
		}
		else
		{
			//otherwise, set brightness coefficient to 1 (multiplying by 1 does nothing)
			extraBright->SetFloat(1.0f);

			//since this is not a light source, it must be affected by the fader
			//update the fader coefficient to the current coefficient from the fader
			fadeCoef->SetFloat(fader.GetCurAlphaScalar());
		}

		//update all lighting params in shader
		dif->SetFloatVector((float*)&d);
		amb->SetFloatVector((float*)&a);
		spec->SetFloatVector((float*)&s);
		shine->SetFloat(ci->Shininess);

		//not using toon shading
		useToon->SetBool(false);
		toon->SetResource(NULL);

		//tell the shader if material has a texture
		useTex->SetBool((_material[i].hasTexture() && texResViews[i] != NULL));
		if (extendedData.getAnimated(i))
		{
			//if it is animated, get the current texture from the extended data
			//calculated automatically based on time and settings in extended data
			useTex->SetBool(true);
			tex->SetResource(extendedData.getTexture(i));
		}
		else
		{
			//not animated, so we get the static texture from the material
			//if the material has a texture and it was sucessfully loaded into memory
			if (_material[i].hasTexture() && texResViews[i] != NULL)
				tex->SetResource(texResViews[i]);
		}

		//tell the shader what sphere mapping technique to use
		sphType->SetInt(ci->SphereMode);

		//get the sphere map and pass it to the shader
		//if the material has a sphere map and it was sucessfully loaded into memory
		if (_material[i].hasSphere() && sphereResViews[i] != NULL)
			sph->SetResource(sphereResViews[i]);

		//lights off mode not implemented yet
		lightsOff->SetBool(false);

		//update the shader with all the new params we passed to it
		t->GetPassByIndex(0)->Apply(0);

		//make sure D3D is set to use the vertex and index buffer
		UINT stride = sizeof(MMDVERTEX);
		UINT offset = 0;
		dev->IASetVertexBuffers(0, 1, &v_buffer, &stride, &offset);
		dev->IASetIndexBuffer(i_buffer, DXGI_FORMAT_R16_UINT, 0);
		dev->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);

		//draw only the number of indices in this material
		dev->DrawIndexed(ci->ApexCount, finSurfaces, 0);
		finSurfaces += ci->ApexCount;
	}
}
/* PMDObject::renderDebug: render model debug */
void PMDObject::renderDebug(TextRenderer * text)
{
   btVector3 pos, x, y;
   unsigned long i, j;
   float dest;
   MotionPlayer *motionPlayer;

   /* render debug */
   m_pmd.renderDebug();

   /* render model name */
   glDisable(GL_LIGHTING);

   glColor4f(0.0f, 1.0f, 0.0f, 1.0f);
   glPushMatrix();
   pos = m_pmd.getCenterBone()->getTransform()->getOrigin();
   glTranslatef(pos.x() + 2.0f, m_pmd.getMaxHeight() + 2.0f , pos.z());
   if(m_alias)
      text->drawString(m_alias);
   if(m_pmd.getName()) {
      text->drawString("(");
      text->drawString(m_pmd.getName());
      text->drawString(")");
   }
   glPopMatrix();

   /* render motion names */
   glColor4f(0.0, 1.0f, 1.0f, 1.0f);
   for(dest = 0.7f, motionPlayer = getMotionManager()->getMotionPlayerList(); motionPlayer; motionPlayer = motionPlayer->next) {
      if(motionPlayer->active) {
         glPushMatrix();
         glTranslatef(pos.x() + 2.0f + dest, m_pmd.getMaxHeight() + 2.0f - dest, pos.z() + dest);
         text->drawString(motionPlayer->name);
         glPopMatrix();
         dest += 0.7f;
      }
   }

   /* render motion skeletons */
   dest = 0.7f;
   for(motionPlayer = getMotionManager()->getMotionPlayerList(); motionPlayer; motionPlayer = motionPlayer->next) {
      if(motionPlayer->active) {
         glPushMatrix();
         MotionControllerBoneElement *b = motionPlayer->mc.getBoneCtrlList();
         glTranslatef(pos.x() + 7.0f + dest, m_pmd.getMaxHeight() + 1.0f - dest, pos.z() + dest);
         glScalef(0.2f, 0.2f, 0.2f);
         m_pmd.resetBone();
         /* temporary apply bone positions / rotations of this motion to bones */
         for (i = 0; i < motionPlayer->mc.getNumBoneCtrl(); i++) {
            if (motionPlayer->ignoreStatic == true && b[i].motion->numKeyFrame <= 1)
               continue;
            b[i].bone->setCurrentPosition(&(b[i].pos));
            b[i].bone->setCurrentRotation(&(b[i].rot));
         }
         /* update bone position */
         m_pmd.updateBone();
         /* draw bones */
         for (i = 0; i < motionPlayer->mc.getNumBoneCtrl(); i++) {
            if (b[i].bone->hasMotionIndependency() == true || b[i].bone->isSimulated() || b[i].bone->getType() == NO_DISP)
               continue;
            /* do not draw IK target bones if the IK chain is under simulation */
            if (b[i].bone->getType() == IK_TARGET && b[i].bone->getParentBone() && b[i].bone->getParentBone()->isSimulated()) continue;
            if (b[i].bone->getType() == UNDER_ROTATE) {
               /* if target bone is also controlled in this motion, draw it */
               for (j = 0; j < motionPlayer->mc.getNumBoneCtrl(); j++) {
                  if (motionPlayer->ignoreStatic == true && b[j].motion->numKeyFrame <= 1)
                     continue;
                  if (b[i].bone->getTargetBone() == b[j].bone)
                     break;
               }
               if (j >= motionPlayer->mc.getNumBoneCtrl())
                  continue;
            }
            /* draw bone */
            x = b[i].bone->getTransform()->getOrigin();
            y = b[i].bone->getParentBone()->getTransform()->getOrigin();
            if (motionPlayer->ignoreStatic == true && b[i].motion->numKeyFrame <= 1) {
               glColor4f(0.4f, 0.4f, 0.4f, 1.0f);
            } else if (b[i].bone == m_pmd.getCenterBone()) {
               glColor4f(1.0f, 0.4f, 0.4f, 1.0f);
            } else if (b[i].bone->getType() == IK_DESTINATION) {
               glColor4f(1.0f, 0.2f, 0.2f, 1.0f);
            } else {
               glColor4f(1.0f, 0.0f, 1.0f, 1.0f);
            }
            glBegin(GL_LINES);
            glVertex3f(x.x(), x.y(), x.z());
            glVertex3f(y.x(), y.y(), y.z());
            glEnd();
            if (b[i].bone->getType() == IK_DESTINATION) {
               /* when an IK is controlled in this motion, the releavant bones under the IK should also be drawn */
               for (j = 0; j < motionPlayer->mc.getNumBoneCtrl(); j++) {
                  if (motionPlayer->ignoreStatic == true && b[j].motion->numKeyFrame <= 1)
                     continue;
                  if (b[j].bone->hasMotionIndependency() == true || b[j].bone->isSimulated())
                     continue;
                  if (b[j].bone->getType() == UNDER_IK && b[j].bone->getTargetBone() == b[i].bone) {
                     x = b[j].bone->getTransform()->getOrigin();
                     y = b[j].bone->getParentBone()->getTransform()->getOrigin();
                     glColor4f(1.0f, 0.0f, 1.0f, 1.0f);
                     glBegin(GL_LINES);
                     glVertex3f(x.x(), x.y(), x.z());
                     glVertex3f(y.x(), y.y(), y.z());
                     glEnd();
                  }
               }
            }
         }
         glPopMatrix();
         dest += 0.7f;
      }
   }

   /* restore the bone positions */
   updateMotion(0.0);

   glEnable(GL_LIGHTING);
}
Ejemplo n.º 5
0
void ResourceWindow::updateGUI()
{

	SmartBody::SBScene* scene = SmartBody::SBScene::getScene();
	SmartBody::SBAssetManager* assetManager = scene->getAssetManager();

	resourceTree->sortorder(FL_TREE_SORT_ASCENDING);	
	// update path tree	
	updatePath(getTreeFromName("script path"), SmartBody::SBScene::getScene()->getAssetPaths("script"));	
	updatePath(getTreeFromName("motion path"), SmartBody::SBScene::getScene()->getAssetPaths("motion"));	
	updatePath(getTreeFromName("audio path"), SmartBody::SBScene::getScene()->getAssetPaths("audio"));	
	updatePath(getTreeFromName("mesh path"), SmartBody::SBScene::getScene()->getAssetPaths("mesh"));	
	

	// update sequence file list

	const std::vector<std::string> scriptPaths = SmartBody::SBScene::getScene()->getAssetPaths("script");
	resourceTree->clear_children(getTreeFromName("scriptfiles"));
	for (size_t p = 0; p < scriptPaths.size(); p++)
	{
		updateScriptFiles(getTreeFromName("scriptfiles"), scriptPaths[p]);
	}	

	// update runtime scripts
	resourceTree->clear_children(getTreeFromName("script"));
	std::vector<std::string> scriptName = scene->getScriptNames();
	for (size_t i = 0; i < scriptName.size(); i++)
	{
		SmartBody::SBScript* script = scene->getScript(scriptName[i]);
		updateScript(getTreeFromName("script"), script);
	}

	// update skeleton
	resourceTree->clear_children(getTreeFromName("skeleton"));
	std::vector<std::string> skeletons = scene->getSkeletonNames();
	for (size_t c = 0; c < skeletons.size(); c++)
	{
		SmartBody::SBSkeleton * skel = scene->getSkeleton(skeletons[c]);
		updateSkeleton(getTreeFromName("skeleton"), skel);
	}

	// update joint maps
	resourceTree->clear_children(getTreeFromName("jointmap"));	
	SmartBody::SBJointMapManager* jointMapManager = scene->getJointMapManager();
	std::vector<std::string> jointMapNames = jointMapManager->getJointMapNames();
	for (std::vector<std::string>::iterator iter = jointMapNames.begin();
		 iter != jointMapNames.end(); 
		 iter++)
	{
		Fl_Tree_Item* boneMapItem = resourceTree->add(getTreeFromName("jointmap"), (*iter).c_str());
		updateJointMap(boneMapItem, jointMapManager->getJointMap((*iter)));
	}

	// update gesture maps
	resourceTree->clear_children(getTreeFromName("gesturemap"));
	SmartBody::SBGestureMapManager* gestureMapManager = scene->getGestureMapManager();
	std::vector<std::string> gestureMapNames = gestureMapManager->getGestureMapNames();
	for (std::vector<std::string>::iterator iter = gestureMapNames.begin();
		 iter != gestureMapNames.end(); 
		 iter++)
	{
		Fl_Tree_Item* gestureMapItem = resourceTree->add(getTreeFromName("gesturemap"), (*iter).c_str());
		updateGestureMap(gestureMapItem, gestureMapManager->getGestureMap((*iter)));
	}

	// update motion map
	resourceTree->clear_children(getTreeFromName("motion"));
	std::vector<std::string> motionNames = scene->getMotionNames();
	for (size_t i = 0; i < motionNames.size(); i++)
	{
		//resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str());
		SmartBody::SBMotion * motion = scene->getMotion(motionNames[i]);
		updateMotion(getTreeFromName("motion"), motion);
	}

	SmartBody::SBAnimationBlendManager* blendManager = scene->getBlendManager();
	// update animation blend map
	resourceTree->clear_children(getTreeFromName("blend"));
	std::vector<std::string> blendNames = blendManager->getBlendNames();
	for (size_t i = 0; i < blendNames.size(); i++)
	{
		//resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str());
		SmartBody::SBAnimationBlend * blend = blendManager->getBlend(blendNames[i]);
		updateAnimationBlend(getTreeFromName("blend"), blend);
	}

	// update blend transition map
	resourceTree->clear_children(getTreeFromName("transition"));
	std::vector<std::string> transitionNames = blendManager->getTransitionNames();
	for (size_t i = 0; i < transitionNames.size(); i++)
	{
		//resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str());
		SmartBody::SBAnimationTransition * transition = blendManager->getTransitionByName(transitionNames[i]);
		updateBlendTransition(getTreeFromName("transition"), transition);
	}

	// update mesh map
	resourceTree->clear_children(getTreeFromName("mesh"));
	std::vector<std::string> meshNames = assetManager->getDeformableMeshNames();
	for (size_t i = 0; i < meshNames.size(); i++)
	{
		DeformableMesh* mesh = assetManager->getDeformableMesh(meshNames[i]);
		Fl_Tree_Item* meshItem = resourceTree->add(getTreeFromName("mesh"), mesh->getName().c_str());
		updateMesh(meshItem, mesh);
	}


	// update face definition map
	resourceTree->clear_children(getTreeFromName("facedefinition"));
	std::vector<std::string> faceNames = scene->getFaceDefinitionNames();
	for (size_t i = 0; i < faceNames.size(); i++)
	{
		//resourceTree->add(treeItemList[ITEM_MOTION],mi->first.c_str());
		SmartBody::SBFaceDefinition * face = scene->getFaceDefinition(faceNames[i]);
		if (!face)
			continue;
		Fl_Tree_Item* faceTree = resourceTree->add(getTreeFromName("facedefinition"), face->getName().c_str());
		updateFaceDefinition(faceTree, face);
	}

	// update event handler list
	SmartBody::SBEventManager* eventManager = SmartBody::SBScene::getScene()->getEventManager();
	std::map<std::string, SmartBody::SBEventHandler*>& eventMap = eventManager->getEventHandlers();
	std::map<std::string, SmartBody::SBEventHandler*>::iterator ei;
	resourceTree->clear_children(getTreeFromName("eventhandler"));
	for ( ei  = eventMap.begin();
		  ei != eventMap.end();
		  ei++)
	{
		updateEventHandler(getTreeFromName("eventhandler"), ei->second);
	}
	// Below are instance objects :

	// update pawn objects
	resourceTree->clear_children(getTreeFromName("pawn"));
	const std::vector<std::string>& pawnNames = scene->getPawnNames();
	for (size_t i = 0; i < pawnNames.size(); i++)
	{
		SmartBody::SBPawn* pawn = scene->getPawn(pawnNames[i]);
		updatePawn(getTreeFromName("pawn"), pawn);
	}

	// update characters
	resourceTree->clear_children(getTreeFromName("character"));
	const std::vector<std::string>& charNames = scene->getCharacterNames();
	for (size_t i = 0; i < charNames.size(); i++)
	{
		SmartBody::SBCharacter* character = scene->getCharacter(charNames[i]);
		resourceTree->sortorder(FL_TREE_SORT_ASCENDING);
		updateCharacter(getTreeFromName("character"), character);
	}

	
// 	for (SBPhysicsObjMap::iterator iter = phySim->getPhysicsObjMap().begin();
// 		 iter != phySim->getPhysicsObjMap().end();
// 		 iter++)
// 	{
// 		SBPhysicsObj* obj = (*iter).second;
// 		if (dynamic_cast<SbmJointObj*>(obj) == NULL)
// 		{
// 
// 		}
// 	}

	// update services
	SmartBody::SBServiceManager* serviceManager = scene->getServiceManager();
	std::map<std::string, SmartBody::SBService*>& serviceMap = serviceManager->getServices();

	resourceTree->clear_children(getTreeFromName("service"));
	for (std::map<std::string, SmartBody::SBService*>::iterator iter = serviceMap.begin();
		iter != serviceMap.end();
		iter++)
	{
		SmartBody::SBService* service = (*iter).second;
		resourceTree->sortorder(FL_TREE_SORT_ASCENDING);	
		SmartBody::SBPhysicsManager* phyManager = dynamic_cast<SmartBody::SBPhysicsManager*>(service);
		if (phyManager)
			updatePhysicsManager(getTreeFromName("service"),phyManager);
		else
			updateService(getTreeFromName("service"), service);
	}

	// update behavior sets
	resourceTree->clear_children(getTreeFromName("behaviorset"));
	std::map<std::string, SmartBody::SBBehaviorSet*>& behaviorSets = scene->getBehaviorSetManager()->getBehaviorSets();
	for (std::map<std::string, SmartBody::SBBehaviorSet*>::iterator iter = behaviorSets.begin();
		 iter != behaviorSets.end();
		 iter++)
	{
		SmartBody::SBBehaviorSet* behaviorSet = (*iter).second;
		updateBehaviorSet(getTreeFromName("behaviorset"), behaviorSet);
	}


	_dirty = false;

	if (_firstTime)
	{
		hideTree();
		_firstTime = false;
	}
}