JointPtr Joint::clone() const { //TRACER_VERBOSE_ENTER_SCOPE("Joint[%s]@%p::clone()",id_.str(),this); JointPtr newJoint(new Joint(*this)); //TRACER_VERBOSE_PRINT("Joint clone is %p",newJoint.get()); return newJoint; }
KeyframeModel::KeyframePtr KeyframeModel::createFrame(KeyframeModel::KeyframePtr oldFrame) { if(!oldFrame) return createFrame(); KeyframePtr newFrame(new motionfile::Keyframe); newFrame->duration = oldFrame->duration; for (unsigned i = 0; i < oldFrame->joints.size(); i++) { motionfile::FrameJoint newJoint(oldFrame->joints[i]); newFrame->joints.push_back(newJoint); } m_currentFrame = newFrame; m_jointManager->setFrame(newFrame); m_ikl->setFrame(newFrame); m_ikr->setFrame(newFrame); return newFrame; }
Skeleton::Skeleton(Json::Value raw_skeleton_json,long time_stamp){ Json::Value joints_json = raw_skeleton_json.get("joints",NULL); Json::Value client_id = raw_skeleton_json.get("client_id",NULL); Json::Value pos_x = raw_skeleton_json.get("pos_x",NULL); Json::Value pos_y = raw_skeleton_json.get("pos_y",NULL); Json::Value pos_z = raw_skeleton_json.get("pos_z",NULL); Json::Value sensor_id = raw_skeleton_json.get("sensor_id",NULL); Json::Value skeleton_id = raw_skeleton_json.get("skeleton_id",NULL); Json::Value tracking_mode = raw_skeleton_json.get("trackingMode",NULL); vector<Joint> newJoints; for(unsigned short joint=0;joint<joints_json.size();joint++){ Joint::JointType type = (Joint::JointType)joint; Json::Value tracking_mode_joint = joints_json[joint].get("trackedMode",NULL); Joint::Mode trackingType; if(tracking_mode_joint!=NULL){ string trackingMode = joints_json[joint].get("trackedMode",NULL).asString(); if(trackingMode=="Tracked"){ trackingType = Joint::Mode::Tracked; }else if(trackingMode=="NotTracked"){ trackingType = Joint::Mode::NotTracked; }else if(trackingMode=="Inferred"){ trackingType = Joint::Mode::Inferred; } }else{ trackingType = Joint::Mode::NotTracked; } Joint newJoint( type, joints_json[joint].get("X",NULL).asDouble(), joints_json[joint].get("Y",NULL).asDouble(), joints_json[joint].get("Z",NULL).asDouble(), trackingType ); newJoints.push_back(newJoint); } this->SetJoints(newJoints); if(tracking_mode!=NULL&&tracking_mode.asString()=="Tracked"){ this->TrackingMode = Skeleton::Tracked; }else{ this->TrackingMode = Skeleton::PositionOnly; } this->client_id = client_id.asUInt(); this->pos_x = pos_x.asDouble(); this->pos_y = pos_y.asDouble(); this->pos_z = pos_z.asDouble(); this->skeleton_id = skeleton_id.asUInt(); this->sensor_id = sensor_id.asString(); this->time_stamp = time_stamp; this->shared = false; }
/* ============== idDragEntity::Update ============== */ void idDragEntity::Update( idPlayer *player ) { idVec3 viewPoint, origin; idMat3 viewAxis, axis; trace_t trace; idEntity *newEnt; idAngles angles; jointHandle_t newJoint(INVALID_JOINT); idStr newBodyName; player->GetViewPos( viewPoint, viewAxis ); // if no entity selected for dragging if ( !dragEnt.GetEntity() ) { if ( player->usercmd.buttons & BUTTON_ATTACK ) { gameLocal.clip.TracePoint( trace, viewPoint, viewPoint + viewAxis[0] * MAX_DRAG_TRACE_DISTANCE, (CONTENTS_SOLID|CONTENTS_RENDERMODEL|CONTENTS_BODY), player ); if ( trace.fraction < 1.0f ) { newEnt = gameLocal.entities[ trace.c.entityNum ]; if ( newEnt ) { // Ish: We sometimes want to select things that are bound /* if ( newEnt->GetBindMaster() ) { if ( newEnt->GetBindJoint() ) { trace.c.id = JOINT_HANDLE_TO_CLIPMODEL_ID( newEnt->GetBindJoint() ); } else { trace.c.id = newEnt->GetBindBody(); } newEnt = newEnt->GetBindMaster(); } */ if ( newEnt->IsType( idAFEntity_Base::Type ) && static_cast<idAFEntity_Base *>(newEnt)->IsActiveAF() ) { idAFEntity_Base *af = static_cast<idAFEntity_Base *>(newEnt); // joint being dragged newJoint = CLIPMODEL_ID_TO_JOINT_HANDLE( trace.c.id ); // get the body id from the trace model id which might be a joint handle trace.c.id = af->BodyForClipModelId( trace.c.id ); // get the name of the body being dragged newBodyName = af->GetAFPhysics()->GetBody( trace.c.id )->GetName(); } else if ( !newEnt->IsType( idWorldspawn::Type ) ) { if ( trace.c.id < 0 ) { newJoint = CLIPMODEL_ID_TO_JOINT_HANDLE( trace.c.id ); } else { newJoint = INVALID_JOINT; } newBodyName = ""; } else { newJoint = INVALID_JOINT; newEnt = NULL; } } if ( newEnt ) { dragEnt = newEnt; selected = newEnt; joint = newJoint; id = trace.c.id; bodyName = newBodyName; if ( !cursor ) { cursor = ( idCursor3D * )gameLocal.SpawnEntityType( idCursor3D::Type ); } idPhysics *phys = dragEnt.GetEntity()->GetPhysics(); localPlayerPoint = ( trace.c.point - viewPoint ) * viewAxis.Transpose(); origin = phys->GetOrigin( id ); axis = phys->GetAxis( id ); localEntityPoint = ( trace.c.point - origin ) * axis.Transpose(); cursor->drag.Init( g_dragDamping.GetFloat() ); cursor->drag.SetPhysics( phys, id, localEntityPoint ); cursor->Show(); if ( phys->IsType( idPhysics_AF::Type ) || phys->IsType( idPhysics_RigidBody::Type ) || phys->IsType( idPhysics_Monster::Type ) ) { cursor->BecomeActive( TH_THINK ); } } } } } // if there is an entity selected for dragging idEntity *drag = dragEnt.GetEntity(); if ( drag ) { if ( !( player->usercmd.buttons & BUTTON_ATTACK ) ) { StopDrag(); return; } cursor->SetOrigin( viewPoint + localPlayerPoint * viewAxis ); cursor->SetAxis( viewAxis ); cursor->drag.SetDragPosition( cursor->GetPhysics()->GetOrigin() ); renderEntity_t *renderEntity = drag->GetRenderEntity(); idAnimator *dragAnimator = drag->GetAnimator(); if ( joint != INVALID_JOINT && renderEntity && dragAnimator ) { dragAnimator->GetJointTransform( joint, gameLocal.time, cursor->draggedPosition, axis ); cursor->draggedPosition = renderEntity->origin + cursor->draggedPosition * renderEntity->axis; gameRenderWorld->DrawText( va( "%s\n%s\n%s, %s", drag->GetName(), drag->GetType()->classname, dragAnimator->GetJointName( joint ), bodyName.c_str() ), cursor->GetPhysics()->GetOrigin(), 0.1f, colorWhite, viewAxis, 1 ); } else { cursor->draggedPosition = cursor->GetPhysics()->GetOrigin(); gameRenderWorld->DrawText( va( "%s\n%s\n%s", drag->GetName(), drag->GetType()->classname, bodyName.c_str() ), cursor->GetPhysics()->GetOrigin(), 0.1f, colorWhite, viewAxis, 1 ); } } // if there is a selected entity if ( selected.GetEntity() && g_dragShowSelection.GetBool() ) { // draw the bbox of the selected entity renderEntity_t *renderEntity = selected.GetEntity()->GetRenderEntity(); if ( renderEntity ) { gameRenderWorld->DebugBox( colorYellow, idBox( renderEntity->bounds, renderEntity->origin, renderEntity->axis ) ); } } }