void psCharAppearance::ProcessAttach(csRef<iMeshWrapper> meshWrap, csRef<iSpriteCal3DSocket> socket) { if(!socket.IsValid()) return; CS_ASSERT(socket.IsValid()); meshWrap->GetFlags().Set(CS_ENTITY_NODECAL); const char* socketName = socket->GetName(); // Given a socket name of "righthand", we're looking for a key in the form of "socket_righthand" csString keyName = "socket_"; keyName += socketName; // Variables for transform to be specified float trans_x = 0, trans_y = 0.0, trans_z = 0, rot_x = -PI/2, rot_y = 0, rot_z = 0; csRef<iObjectIterator> it = meshWrap->GetFactory()->QueryObject()->GetIterator(); while ( it->HasNext() ) { csRef<iKeyValuePair> key ( scfQueryInterface<iKeyValuePair> (it->Next())); if (key && keyName == key->GetKey()) { sscanf(key->GetValue(),"%f,%f,%f,%f,%f,%f",&trans_x,&trans_y,&trans_z,&rot_x,&rot_y,&rot_z); } } meshWrap->QuerySceneNode()->SetParent( baseMesh->QuerySceneNode ()); socket->SetMeshWrapper( meshWrap ); socket->SetTransform( csTransform(csZRotMatrix3(rot_z)*csYRotMatrix3(rot_y)*csXRotMatrix3(rot_x), csVector3(trans_x,trans_y,trans_z)) ); usedSlots.PushSmart(socketName); }
//--------------------------------------------------------------------------- csTransform csTransform::GetReflect (const csPlane3 &pl) { // Suppose that n is the plane normal in the direction of th reflection. // Suppose that u is the unit vector in the direction of the reflection // normal. For any vector v, the component of v in the direction of // u is equal to (v * u) * u. Thus, if v is reflected across a plane // through the origin with the given normal, the resulting vector is // v' = v - 2 * [ (v * u) * u ] = v - 2 [ (v * n) * n ] / (n * n) // // x = <1,0,0> => x' = <1,0,0> - 2 ( n.x * n ) / (n*n) // y = <0,1,0> => y' = <0,1,0> - 2 ( n.y * n ) / (n*n) // z = <0,0,1> => z' = <0,0,1> - 2 ( n.z * n ) / (n*n) // // 3x3 transformation matrix = [x' y' z'] float i_normsq = 1 / (pl.norm * pl.norm); csVector3 xvec = (-2 * pl.norm.x * i_normsq) * pl.norm; csVector3 yvec = (-2 * pl.norm.y * i_normsq) * pl.norm; csVector3 zvec = (-2 * pl.norm.z * i_normsq) * pl.norm; xvec.x += 1; yvec.y += 1; zvec.z += 1; return csTransform ( csMatrix3 ( xvec.x, yvec.x, zvec.x, xvec.y, yvec.y, zvec.y, xvec.z, yvec.z, zvec.z), /* neworig = */(-2 * pl.DD * i_normsq) * pl.norm); }
void psCharAppearance::ApplyRider(csRef<iMeshWrapper> mesh) { csRef<iSpriteCal3DState> mountstate = scfQueryInterface<iSpriteCal3DState> (mesh->GetMeshObject()); csRef<iSpriteCal3DSocket> socket = mountstate->FindSocket( "back" ); if ( !socket ) { Error1("Socket back not found."); return; } baseMesh->GetFlags().Set(CS_ENTITY_NODECAL); const char* socketName = socket->GetName(); // Given a socket name of "righthand", we're looking for a key in the form of "socket_righthand" csString keyName = "socket_"; keyName += socketName; // Variables for transform to be specified float trans_x = 0, trans_y = 0.0, trans_z = 0, rot_x = -PI/2, rot_y = 0, rot_z = 0; csRef<iObjectIterator> it = baseMesh->GetFactory()->QueryObject()->GetIterator(); while ( it->HasNext() ) { csRef<iKeyValuePair> key ( scfQueryInterface<iKeyValuePair> (it->Next())); if (key && keyName == key->GetKey()) { sscanf(key->GetValue(),"%f,%f,%f,%f,%f,%f",&trans_x,&trans_y,&trans_z,&rot_x,&rot_y,&rot_z); } } baseMesh->QuerySceneNode()->SetParent( mesh->QuerySceneNode ()); socket->SetMeshWrapper( baseMesh ); socket->SetTransform( csTransform(csZRotMatrix3(rot_z)*csYRotMatrix3(rot_y)*csXRotMatrix3(rot_x), csVector3(trans_x,trans_y,trans_z)) ); }
csTransform operator * ( const csTransform &t1, const csReversibleTransform &t2) { return csTransform (t1.m_o2t * t2.m_o2t, t2.v_o2t + t2.m_t2o * t1.v_o2t); }