// intersect a plane bool TXOctree::TouchPlane(const CVector3f& n, float d, float bias) { bool sa = n.GetX()>=0, sb = n.GetY()>=0, sc = n.GetZ()>=0; float p1x = m_min.GetX(), p1y, p1z, p2x = m_max.GetX(), p2y, p2z; if (sb == sa) { p1y = m_min.GetY(); p2y = m_max.GetY(); } else { p1y = m_max.GetY(); p2y = m_min.GetY(); } if (sc == sa) { p1z = m_min.GetZ(); p2z = m_max.GetZ(); } else { p1z = m_max.GetZ(); p2z = m_min.GetZ(); } float dot1 = n.GetX()*p1x + n.GetY()*p1y + n.GetZ()*p1z + d ; float dot2 = n.GetX()*p2x + n.GetY()*p2y + n.GetZ()*p2z + d ; bool sd1 = dot1 >= bias; bool sd2 = dot2 >= bias; return (sd1 != sd2); }
/** Transform the vector by m. Use this method to do general vector transformation. \param[in] m The transformation matrix. */ Void CVector3f::Transform( const CMatrix4x4f& m ) { CVector3f tmp = *this; x = m._11*tmp.GetX() + m._21*tmp.GetY() + m._31*tmp.GetZ(); y = m._12*tmp.GetX() + m._22*tmp.GetY() + m._32*tmp.GetZ(); z = m._13*tmp.GetX() + m._23*tmp.GetY() + m._33*tmp.GetZ(); }
/** Initialize the plane from a points and a normal vector */ Void CPlane::Set( const CVector3f& pos, const CVector3f& norm ) { CVector3f n = norm; n.Normalize(); m_Coef.SetX( n.GetX() ); m_Coef.SetY( n.GetY() ); m_Coef.SetZ( n.GetZ() ); m_Coef.SetW( -(m_Coef.GetX()*pos.GetX() + m_Coef.GetY()*pos.GetY() + m_Coef.GetZ()*pos.GetZ() ) ); }
/** Implemented but not tested */ Void CVector3f::SetFromReflectionVector( const CVector3f& input, const CVector3f& normal ) { Float32 dot; dot = input.DotProduct( normal ); x = input.GetX() - 2 * dot * normal.GetX(); y = input.GetY() - 2 * dot * normal.GetY(); z = input.GetZ() - 2 * dot * normal.GetZ(); }
// place a triangle mesh in the grid void TXGrid3D::PlaceIntoGrid(TXGeometry *geom) { m_min = CVector3f(FLT_MAX, FLT_MAX, FLT_MAX); m_max = CVector3f(-FLT_MAX, -FLT_MAX, -FLT_MAX); // compute bounding box int totalTriangles = 0; TXTriangle* tp; CVector3f p; for(ULONG t=0;t<geom->m_triangles.size();t++) { tp = geom->m_triangles[t]; totalTriangles++; for(int i=0;i<3;i++) { p = tp->m_v[i]->m_pos; m_min.Set( MIN(m_min.GetX(),p.GetX()), MIN(m_min.GetY(),p.GetY()), MIN(m_min.GetZ(),p.GetZ()) ); m_max.Set(MAX(m_max.GetX(),p.GetX()), MAX(m_max.GetY(),p.GetY()), MAX(m_max.GetZ(),p.GetZ()) ); } } Application().LogMessage(L"Total Triangles : "+(CString)totalTriangles); // select grid size int grid_size; if (totalTriangles <= 10000) grid_size = 10; else if (totalTriangles <= 40000) grid_size = 15; else grid_size = 20; // create grid CreateGrid(grid_size); m_xstep = (m_max.GetX() - m_min.GetX()) / m_size; m_ystep = (m_max.GetY() - m_min.GetY()) / m_size; m_zstep = (m_max.GetZ() - m_min.GetZ()) / m_size; for(ULONG t=0;t<geom->m_triangles.size();t++) { PlaceTriangle(geom->m_triangles[t]); } }
Bool CVector3f::operator!=( const CVector3f& V ) const { if((x != V.GetX() ) || (y != V.GetY() ) || (z != V.GetZ() )) return TRUE; return FALSE; }
/** Compute the linear interpolation between this vector and v. The interpolation is parameterized by t. \param[in] v the second vector. \param[in] t the parametrization value between [ O.O , 1.0 ] \return The interpoled vector */ CVector3f CVector3f::LinearInterpolation( const CVector3f& v, Float32 t) { DebugAssert( t >= 0.0f && t <= 1.0f ); CVector3f r( x + t*(v.GetX() -x), y + t*(v.GetY() -y), z + t*(v.GetZ() -z) ); return r; }
Bool CVector3f::operator==( const CVector3f& V ) const { if((x == V.GetX() ) && (y == V.GetY() ) && (z == V.GetZ() )) return TRUE; return FALSE; }
/** Transform the vector by m and then divide by W component. Use this method to transform a position in space. \param[in] m The transformation matrix. */ Void CVector3f::TransformPosition( const CMatrix4x4f& m ) { CVector3f tmp = *this; Float32 w = 1.0f; x = m._11*tmp.GetX() + m._21*tmp.GetY() + m._31*tmp.GetZ() + m._41*1 ; y = m._12*tmp.GetX() + m._22*tmp.GetY() + m._32*tmp.GetZ() + m._42*1 ; z = m._13*tmp.GetX() + m._23*tmp.GetY() + m._33*tmp.GetZ() + m._43*1 ; w = m._14*tmp.GetX() + m._24*tmp.GetY() + m._34*tmp.GetZ() + m._44*1 ; if( w != 0.0f ) { x = x / w; y = y / w; z = z / w; } }
CVector3f CVector3f::Reflect( const CVector3f& n) { Float32 i_dot_n; i_dot_n = DotProduct(n); CVector3f R( x - 2*i_dot_n * n.GetX(), y - 2*i_dot_n * n.GetY(), z - 2*i_dot_n * n.GetZ() ); return R; }
Bool CAABox::IsInside( const CVector3f& pos )const { Float32 x = pos.GetX(); Float32 y = pos.GetY(); Float32 z = pos.GetZ(); return ( x>m_Minimum.GetX()&&x<m_Maximum.GetX() ) && ( y>m_Minimum.GetY()&&y<m_Maximum.GetY() ) && ( z>m_Minimum.GetZ()&&z<m_Maximum.GetZ() ) ; }
Void CAABox::AddPoint( const CVector3f& point ) { if( IsEmpty() ) { m_Minimum = point; m_Maximum = point; } else { if ( point.GetX() > m_Maximum.GetX() ) m_Maximum.SetX( point.GetX() ); if ( point.GetY() > m_Maximum.GetY() ) m_Maximum.SetY( point.GetY() ); if ( point.GetZ() > m_Maximum.GetZ() ) m_Maximum.SetZ( point.GetZ() ); if ( point.GetX() < m_Minimum.GetX() ) m_Minimum.SetX( point.GetX() ); if ( point.GetY() < m_Minimum.GetY() ) m_Minimum.SetY( point.GetY() ); if ( point.GetZ() < m_Minimum.GetZ() ) m_Minimum.SetZ( point.GetZ() ); } }
/** Compute the position of a point projected orthogonally on the plane. (according to the plane's normal) */ Bool CPlane::OrthogonalProjection( const CVector3f& point, CVector3f& projectedPoint ) { CVector3f planeNormal = GetNormal(); Float32 nx, ny, nz, px, py, pz, d, distFromPlane, denum; nx = m_Coef.GetX(); ny = m_Coef.GetY(); nz = m_Coef.GetZ(); d = m_Coef.GetW(); px = point.GetX(); py = point.GetY(); pz = point.GetZ(); denum = ( nx*nx + ny*ny + nz*nz ); if( denum == 0.0f ) return FALSE; distFromPlane = ( nx*px + ny*py + nz*pz + d ) / denum; projectedPoint = point - planeNormal * distFromPlane; return TRUE; }
/** Return TRUE, if the ray intersect the plane. \param ray The input ray \param intersection the intersection distance from the origin of the ray \return TRUE if any intersection. */ Float32 CPlane::Intersect( const CRay& ray ) const { CVector3f origin = ray.Origin, dir = ray.Direction; Float32 divider, intersection; dir.Normalize(); // Take line equation as: P = origin + t * dir // Then plug line equation into plane equation: // a*(origin.x + t*dir.x) + a*(origin.y + t*dir.y) + a*(origin.z + t*dir.z) + d = 0 // solve for t : divider = (m_Coef.GetX()*dir.GetX() + m_Coef.GetY()*dir.GetY() + m_Coef.GetZ()*dir.GetZ()); if( divider == 0.0f ) return FALSE; intersection = -(m_Coef.GetX()*origin.GetX() + m_Coef.GetY()*origin.GetY() + m_Coef.GetZ()*origin.GetZ() + m_Coef.GetW()) / divider; if(intersection < 0.0f) return -1.0f; return intersection; }
// intersect a box bool TXDualEdge::Touch(const CVector3f& minp, const CVector3f& maxp) const { int m = 4; CVector3f step; step.Sub(m_dp[1], m_dp[0]); step.ScaleInPlace(1/4); CVector3f A = m_dp[0]; CVector3f B; B.Add(m_dp[0],step); for (int i = 0; i < m; i++) { CVector3f bmin(MIN(A.GetX(),B.GetX()),MIN(A.GetY(),B.GetY()),MIN(A.GetZ(),B.GetZ())); CVector3f bmax(MAX(A.GetX(),B.GetX()),MAX(A.GetY(),B.GetY()),MAX(A.GetZ(),B.GetZ())); if (bmin.GetX() <= maxp.GetX() && minp.GetX() <= bmax.GetX() && bmin.GetY() <= maxp.GetY() && minp.GetY() <= bmax.GetY() && bmin.GetZ() <= maxp.GetZ() && minp.GetZ() <= bmax.GetZ()) return true; A = B; B += step; } return false; }
CVector3f::CVector3f( const CVector3f& other ) { x = other.GetX(); y = other.GetY(); z = other.GetZ(); }
// intersect a ray with the mesh bool TXGrid3D::IntersectRay(const CVector3f& start, const CVector3f& end) { // pick rays m_rays.push_back(TXRay(start, end)); CVector3f dir; dir.Sub(start,end); int idir[3] = { fabs(dir.GetX()) < DBL_EPSILON ? 0 : (dir.GetX() > 0 ? 1 : -1), fabs(dir.GetY()) < DBL_EPSILON ? 0 : (dir.GetY() > 0 ? 1 : -1), fabs(dir.GetZ()) < DBL_EPSILON ? 0 : (dir.GetZ() > 0 ? 1 : -1) }; double dist = 0; CVector3f pos; pos.Sub(end, m_min); int ix = (int)floor((end.GetX() - m_min.GetX())/m_xstep), iy = (int)floor((end.GetY() - m_min.GetY())/m_ystep), iz = (int)floor((end.GetZ() - m_min.GetZ())/m_zstep); double tx = 1.0, ty = 1.0, tz = 1.0; // first cell ix = MIN(MAX(ix, 0), m_size-1); iy = MIN(MAX(iy, 0), m_size-1); iz = MIN(MAX(iz, 0), m_size-1); // intersection test, from end to start while ((dist < 1) && (ix >= 0) && (ix < m_size) &&(iy >= 0) && (iy < m_size) && (iz >= 0) && (iz < m_size)) { int csz = m_grid[ix][iy][iz].size(); for (int i=0; i<csz; i++) { TXGridTriangle* gt = m_grid[ix][iy][iz][i]; double rpdot = dir.Dot(gt->m_n); if (rpdot != 0) { CVector3f tmp; tmp.Sub(gt->m_t->m_v[0]->m_pos,end); double t = tmp.Dot(gt->m_n) / rpdot; if (t > DBL_EPSILON && t < 1) { CVector3f pt; pt.ScaleAdd(t,dir,end); CVector3f pt0,pt1,pt2; pt0.Sub(pt,gt->m_t->m_v[0]->m_pos); pt1.Sub(pt,gt->m_t->m_v[1]->m_pos); pt2.Sub(pt,gt->m_t->m_v[2]->m_pos); if (pt0.Dot(gt->m_en1)> -DBL_EPSILON && pt1.Dot(gt->m_en2)>-DBL_EPSILON && pt2.Dot(gt->m_en3)>-DBL_EPSILON) { m_rays[m_rays.size()-1].m_p = t; return true; } } } } // next cell if (idir[0] != 0) tx = (m_min.GetX() + (ix+(idir[0]+1)/2)*m_xstep - end.GetX()) / dir.GetX(); if (idir[1] != 0) ty = (m_min.GetY() + (iy+(idir[1]+1)/2)*m_ystep - end.GetY()) / dir.GetY(); if (idir[2] != 0) tz = (m_min.GetZ() + (iz+(idir[2]+1)/2)*m_zstep - end.GetZ()) / dir.GetZ(); if ((tx <= ty) && (tx <= tz)) { dist = tx, ix += idir[0]; if (ty == tx) iy += idir[1]; if (tz == tx) iz += idir[2]; } else if (ty <= tz) { dist = ty, iy += idir[1]; if (tz == ty) iz += idir[2]; } else dist = tz, iz += idir[2]; } return false; }
CVector3f CVector3f::operator/( const CVector3f& v) const { return CVector3f(x/v.GetX(),y/v.GetY(),z/v.GetZ() ); }
SICALLBACK MOM_SetAttributes_Evaluate( ICENodeContext& in_ctxt ) { // The current output port being evaluated... ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( ); if(gSimulation == NULL) return CStatus::OK; switch( out_portID ) { case ID_OUT_base: { CDataArrayLong baseData( in_ctxt, ID_IN_base ); CDataArrayLong idData( in_ctxt, ID_IN_id ); rbdID rbd_ID; CIndexSet indexSet( in_ctxt ); // Get the output port array ... CDataArrayLong outData( in_ctxt ); // get all of the input SET data! CDataArrayBool setPosData( in_ctxt, ID_IN_set_position); CDataArrayBool setRotData( in_ctxt, ID_IN_set_orientation); CDataArrayBool setLinvelData( in_ctxt, ID_IN_set_linvelocity); CDataArrayBool setAngvelData( in_ctxt, ID_IN_set_angvelocity); CDataArrayBool setStateData( in_ctxt, ID_IN_set_state); CDataArrayBool setMassData( in_ctxt, ID_IN_set_mass); CDataArrayBool setBounceData( in_ctxt, ID_IN_set_bounce); CDataArrayBool setFrictionData( in_ctxt, ID_IN_set_friction); CDataArrayBool setLindampData( in_ctxt, ID_IN_set_lindamping); CDataArrayBool setAngdampData( in_ctxt, ID_IN_set_angdamping); CDataArrayBool setLintreshData( in_ctxt, ID_IN_set_lintreshold); CDataArrayBool setAngtreshData( in_ctxt, ID_IN_set_angtreshold); // get all of the input data! CDataArrayVector3f posData( in_ctxt, ID_IN_position); CDataArrayVector3f rotData( in_ctxt, ID_IN_orientation); CDataArrayVector3f linvelData( in_ctxt, ID_IN_linvelocity); CDataArrayVector3f angvelData( in_ctxt, ID_IN_angvelocity); CDataArrayLong stateData( in_ctxt, ID_IN_state); CDataArrayFloat massData( in_ctxt, ID_IN_mass); CDataArrayFloat bounceData( in_ctxt, ID_IN_bounce); CDataArrayFloat frictionData( in_ctxt, ID_IN_friction); CDataArrayFloat lindampData( in_ctxt, ID_IN_lindamping); CDataArrayFloat angdampData( in_ctxt, ID_IN_angdamping); CDataArrayFloat lintreshData( in_ctxt, ID_IN_lintreshold); CDataArrayFloat angtreshData( in_ctxt, ID_IN_angtreshold); // get the index set iterator btTransform bodyTransform; CVector3f bodyPos,linvel,angvel; btQuaternion bodyRot; CRotation rot; CQuaternion quat; CVector3f anglesf; CVector3 angles; for(CIndexSet::Iterator it = indexSet.Begin(); it.HasNext(); it.Next()) { rbd_ID.primary = (int)(baseData.IsConstant() ? baseData[0] : baseData[it]); rbd_ID.secondary = (int)(idData.IsConstant() ? idData[0] : idData[it]); btRigidBodyReference * bodyRef = gSimulation->GetRigidBody(rbd_ID); if(bodyRef != NULL) { // take care of the positions if((setPosData.IsConstant() ? setPosData[0] : setPosData[it]) == true) { bodyPos = posData.IsConstant() ? posData[0] : posData[it]; bodyTransform = bodyRef->GetWorldTransform(); bodyTransform.setOrigin(btVector3(bodyPos.GetX(),bodyPos.GetY(),bodyPos.GetZ())); bodyRef->SetWorldTransform(bodyTransform); } // take care of the orientations if((setRotData.IsConstant() ? setRotData[0] : setRotData[it]) == true) { anglesf = rotData.IsConstant() ? rotData[0] : rotData[it]; rot.SetFromXYZAngles(DegreesToRadians(anglesf.GetX()),DegreesToRadians(anglesf.GetY()),DegreesToRadians(anglesf.GetZ())); quat = rot.GetQuaternion(); bodyTransform = bodyRef->GetWorldTransform(); bodyTransform.setRotation(btQuaternion(quat.GetX(),quat.GetY(),quat.GetZ(),quat.GetW())); bodyRef->SetWorldTransform(bodyTransform); } // take care of the linear velocity if((setLinvelData.IsConstant() ? setLinvelData[0] : setLinvelData[it]) == true) { linvel = linvelData.IsConstant() ? linvelData[0] : linvelData[it]; bodyRef->body->setLinearVelocity(btVector3(linvel.GetX(),linvel.GetY(),linvel.GetZ())); } // take care of the angular velocity if((setAngvelData.IsConstant() ? setAngvelData[0] : setAngvelData[it]) == true) { angvel = angvelData.IsConstant() ? angvelData[0] : angvelData[it]; bodyRef->body->setAngularVelocity(btVector3(angvel.GetX(),angvel.GetY(),angvel.GetZ())); } // take care of the state if((setStateData.IsConstant() ? setStateData[0] : setStateData[it]) == true) { int state = stateData.IsConstant() ? stateData[0] : stateData[it]; if(state == 0) bodyRef->body->forceActivationState(ACTIVE_TAG); else if(state == 1) bodyRef->body->forceActivationState(ISLAND_SLEEPING); else if(state == 2) bodyRef->body->forceActivationState(DISABLE_SIMULATION); } // take care of the mass if((setMassData.IsConstant() ? setMassData[0] : setMassData[it]) == true) { // compute the inertia bodyRef->mass = massData.IsConstant() ? massData[0] : massData[it]; btVector3 inertia(0,0,0); if(bodyRef->mass > 0.0f) bodyRef->body->getCollisionShape()->calculateLocalInertia(bodyRef->mass,inertia); bodyRef->body->setMassProps(bodyRef->mass,inertia); } // take care of the bounce if((setBounceData.IsConstant() ? setBounceData[0] : setBounceData[it]) == true) { bodyRef->body->setRestitution(bounceData.IsConstant() ? bounceData[0] : bounceData[it]); } // take care of the friction if((setFrictionData.IsConstant() ? setFrictionData[0] : setFrictionData[it]) == true) { bodyRef->body->setFriction(frictionData.IsConstant() ? frictionData[0] : frictionData[it]); } // take care of the linear damping if((setLindampData.IsConstant() ? setLindampData[0] : setLindampData[it]) == true) { float angdamp = bodyRef->body->getAngularDamping(); bodyRef->body->setDamping(lindampData.IsConstant() ? lindampData[0] : lindampData[it],angdamp); } // take care of the angular damping if((setAngdampData.IsConstant() ? setAngdampData[0] : setAngdampData[it]) == true) { float lindamp = bodyRef->body->getLinearDamping(); bodyRef->body->setDamping(lindamp,angdampData.IsConstant() ? angdampData[0] : angdampData[it]); } // take care of the linear treshold if((setLintreshData.IsConstant() ? setLintreshData[0] : setLintreshData[it]) == true) { float angtresh = bodyRef->body->getAngularSleepingThreshold(); bodyRef->body->setSleepingThresholds(lintreshData.IsConstant() ? lintreshData[0] : lintreshData[it],angtresh); } // take care of the angular treshold if((setAngtreshData.IsConstant() ? setAngtreshData[0] : setAngtreshData[it]) == true) { float lintresh = bodyRef->body->getLinearSleepingThreshold(); bodyRef->body->setSleepingThresholds(lintresh,angtreshData.IsConstant() ? angtreshData[0] : angtreshData[it]); } } outData[it] = rbd_ID.primary; } break; } }; return CStatus::OK; }
CVector3f CVector3f::operator-( const CVector3f& v) const { return CVector3f(x-v.GetX(),y-v.GetY(),z-v.GetZ() ); }
/** Set this vector by the result of the dot product of v& by v2. \param[in] v1 The left operand. \param[in] v1 The right operand. */ Void CVector3f::CrossProduct( const CVector3f& v1, const CVector3f& v2) { x = v1.GetY() * v2.GetZ() - v1.GetZ() * v2.GetY(); y = v1.GetZ() * v2.GetX() - v1.GetX() * v2.GetZ(); z = v1.GetX() * v2.GetY() - v1.GetY() * v2.GetX(); }
CVector3f CVector3f::operator*( const CVector3f& v) const { return CVector3f(x+v.GetX(),y+v.GetY(),z+v.GetZ() ); }
/** Return the value of the cross product between this and v. \param[in] v The right operand. \return the result vector of the cross product. */ CVector3f CVector3f::CrossProduct( const CVector3f& v) const { return CVector3f( y * v.GetZ() - z * v.GetY(), z * v.GetX() - x * v.GetZ(), x * v.GetY() - y * v.GetX() );; }
/** Compute the do product of this vector by v. \param[in] v The right operand ( this beeing the left one ) \return the cross product value */ Float32 CVector3f::DotProduct(const CVector3f& v) const { return x*v.GetX() + y*v.GetY() + z*v.GetZ(); }
Void CGameProperty::SetAsVector3( const CVector3f& d) { m_Tuple3fValue.x = d.GetX(); m_Tuple3fValue.y = d.GetY(); m_Tuple3fValue.z = d.GetZ(); }
Void CPolarCoordinate::SetFromCartesianCoordinate( const CVector3f& vector ) { x = vector.GetLength(); y = MathArcTan2( vector.GetX(), vector.GetZ() ); z = MathArcCos( vector.GetY() / x ); }
XSIPLUGINCALLBACK CStatus nest_LatticeDeform_Evaluate( ICENodeContext& in_ctxt ) { // The current output port being evaluated... ULONG out_portID = in_ctxt.GetEvaluatedOutputPortID( ); switch( out_portID ) { case Array_ID_OUT_Result: { siICENodeDataType dataType; siICENodeStructureType struType; siICENodeContextType contType; in_ctxt.GetPortInfo(Lattice_ID_IN_Point,dataType,struType,contType); // get all of the data that is the same for any structure CDataArrayVector3f SubdivData( in_ctxt, Lattice_ID_IN_Subdivision ); CDataArrayVector3f StepData( in_ctxt, Lattice_ID_IN_Step ); CDataArray2DVector3f ReferenceData( in_ctxt, Lattice_ID_IN_Reference ); CDataArray2DVector3f CurrentData( in_ctxt, Lattice_ID_IN_Current ); CDataArray2DVector3f::Accessor ReferenceDataSub = ReferenceData[0]; CDataArray2DVector3f::Accessor CurrentDataSub = CurrentData[0]; // define the things we need to calculate long subdiv[3]; subdiv[0] = long(floor(SubdivData[0].GetX())); subdiv[1] = long(floor(SubdivData[0].GetY())); subdiv[2] = long(floor(SubdivData[0].GetZ())); long subdiv1[3]; subdiv1[0] = subdiv[0]+1; subdiv1[1] = subdiv[1]+1; subdiv1[2] = subdiv[2]+1; float step[3]; step[0] = 1.0f / StepData[0].GetX(); step[1] = 1.0f / StepData[0].GetY(); step[2] = 1.0f / StepData[0].GetZ(); float steplength = StepData[0].GetLength(); long indexX[8]; long indexY[8]; long indexZ[8]; long index[8]; long lastIndex[3]; lastIndex[0] = -1; lastIndex[1] = -1; lastIndex[2] = -1; CVector3f posCp; CVector3f pos; CVector3f diff[8]; CVector3f motion[8]; CVector3f motionScl[8]; CVector3f deform; float weight[8]; float xyz0[3]; float xyz1[3]; float weightSum; if(struType == siICENodeStructureSingle) { // two behaviours based on the datatype... // Get the output port array ... CDataArrayVector3f outData( in_ctxt ); // Get the input data buffers for each port CDataArrayVector3f PointData( in_ctxt, Lattice_ID_IN_Point ); // iterate each subset! CIndexSet IndexSet( in_ctxt ); for(CIndexSet::Iterator it = IndexSet.Begin(); it.HasNext(); it.Next()) { // first let's find the index inside the box! posCp.Set(PointData[it].GetX(),PointData[it].GetY(),PointData[it].GetZ()); // substract the lowest corner pos.Sub(posCp,ReferenceDataSub[0]); pos.Set(pos.GetX() * step[0], pos.GetY() * step[1], pos.GetZ() * step[2]); xyz0[0] = pos.GetX() - floor(pos.GetX()); xyz0[1] = pos.GetY() - floor(pos.GetY()); xyz0[2] = pos.GetZ() - floor(pos.GetZ()); xyz1[0] = 1.0 - xyz0[0]; xyz1[1] = 1.0 - xyz0[1]; xyz1[2] = 1.0 - xyz0[2]; // calculate the indices (decomposed) indexX[0] = clampl(long(floor(pos.GetX())),0,subdiv[0]); indexY[0] = clampl(long(floor(pos.GetY())),0,subdiv[1]); indexZ[0] = clampl(long(floor(pos.GetZ())),0,subdiv[2]); if(lastIndex[0] != indexX[0] || lastIndex[1] != indexY[0] || lastIndex[2] != indexZ[0]) { indexX[1] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[1] = clampl(indexY[0] ,0,subdiv[1]); indexZ[1] = clampl(indexZ[0] ,0,subdiv[2]); indexX[2] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[2] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[2] = clampl(indexZ[0] ,0,subdiv[2]); indexX[3] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[3] = clampl(indexY[0] ,0,subdiv[1]); indexZ[3] = clampl(indexZ[0]+1 ,0,subdiv[2]); indexX[4] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[4] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[4] = clampl(indexZ[0]+1 ,0,subdiv[2]); indexX[5] = clampl(indexX[0] ,0,subdiv[0]); indexY[5] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[5] = clampl(indexZ[0] ,0,subdiv[2]); indexX[6] = clampl(indexX[0] ,0,subdiv[0]); indexY[6] = clampl(indexY[0] ,0,subdiv[1]); indexZ[6] = clampl(indexZ[0]+1 ,0,subdiv[2]); indexX[7] = clampl(indexX[0] ,0,subdiv[0]); indexY[7] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[7] = clampl(indexZ[0]+1 ,0,subdiv[2]); for(int i=0;i<8;i++) { // compose the indices! index[i] = compose(indexX[i],indexY[i],indexZ[i],subdiv1[1],subdiv1[2]); // calculate the motions motion[i].Sub(CurrentDataSub[index[i]],ReferenceDataSub[index[i]]); } } else { // for performance, remember the last used index lastIndex[0] = indexX[0]; lastIndex[1] = indexY[0]; lastIndex[2] = indexZ[0]; } // compute the weights weight[0] = xyz1[0] * xyz1[1] * xyz1[2]; weight[1] = xyz0[0] * xyz1[1] * xyz1[2]; weight[2] = xyz0[0] * xyz0[1] * xyz1[2]; weight[3] = xyz0[0] * xyz1[1] * xyz0[2]; weight[4] = xyz0[0] * xyz0[1] * xyz0[2]; weight[5] = xyz1[0] * xyz0[1] * xyz1[2]; weight[6] = xyz1[0] * xyz1[1] * xyz0[2]; weight[7] = xyz1[0] * xyz0[1] * xyz0[2]; // sum up all weighted motions deform.SetNull(); for(int i=0;i<8;i++) { motionScl[i].Scale(weight[i],motion[i]); deform.AddInPlace(motionScl[i]); } // output the deformed position outData[it] = deform; } } else { // two behaviours based on the datatype... // Get the output port array ... CDataArray2DVector3f outData( in_ctxt ); // Get the input data buffers for each port CDataArray2DVector3f PointData( in_ctxt, Lattice_ID_IN_Point ); // iterate each subset! CIndexSet IndexSet( in_ctxt ); for(CIndexSet::Iterator it = IndexSet.Begin(); it.HasNext(); it.Next()) { CDataArray2DVector3f::Accessor PointDataSub = PointData[it]; long subCount = PointDataSub.GetCount(); Application().LogMessage(CString((LONG)subCount)); outData.Resize(it,subCount); for(long k=0;k<subCount;k++) { // first let's find the index inside the box! posCp.Set(PointDataSub[k].GetX(),PointDataSub[k].GetY(),PointDataSub[k].GetZ()); // substract the lowest corner pos.Sub(posCp,ReferenceDataSub[0]); pos.Set(pos.GetX() * step[0], pos.GetY() * step[1], pos.GetZ() * step[2]); xyz0[0] = pos.GetX() - floor(pos.GetX()); xyz0[1] = pos.GetY() - floor(pos.GetY()); xyz0[2] = pos.GetZ() - floor(pos.GetZ()); xyz1[0] = 1.0 - xyz0[0]; xyz1[1] = 1.0 - xyz0[1]; xyz1[2] = 1.0 - xyz0[2]; // calculate the indices (decomposed) indexX[0] = clampl(long(floor(pos.GetX())),0,subdiv[0]); indexY[0] = clampl(long(floor(pos.GetY())),0,subdiv[1]); indexZ[0] = clampl(long(floor(pos.GetZ())),0,subdiv[2]); if(lastIndex[0] != indexX[0] || lastIndex[1] != indexY[0] || lastIndex[2] != indexZ[0]) { indexX[1] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[1] = clampl(indexY[0] ,0,subdiv[1]); indexZ[1] = clampl(indexZ[0] ,0,subdiv[2]); indexX[2] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[2] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[2] = clampl(indexZ[0] ,0,subdiv[2]); indexX[3] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[3] = clampl(indexY[0] ,0,subdiv[1]); indexZ[3] = clampl(indexZ[0]+1 ,0,subdiv[2]); indexX[4] = clampl(indexX[0]+1 ,0,subdiv[0]); indexY[4] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[4] = clampl(indexZ[0]+1 ,0,subdiv[2]); indexX[5] = clampl(indexX[0] ,0,subdiv[0]); indexY[5] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[5] = clampl(indexZ[0] ,0,subdiv[2]); indexX[6] = clampl(indexX[0] ,0,subdiv[0]); indexY[6] = clampl(indexY[0] ,0,subdiv[1]); indexZ[6] = clampl(indexZ[0]+1 ,0,subdiv[2]); indexX[7] = clampl(indexX[0] ,0,subdiv[0]); indexY[7] = clampl(indexY[0]+1 ,0,subdiv[1]); indexZ[7] = clampl(indexZ[0]+1 ,0,subdiv[2]); for(int i=0;i<8;i++) { // compose the indices! index[i] = compose(indexX[i],indexY[i],indexZ[i],subdiv1[1],subdiv1[2]); // calculate the motions motion[i].Sub(CurrentDataSub[index[i]],ReferenceDataSub[index[i]]); } } else { // for performance, remember the last used index lastIndex[0] = indexX[0]; lastIndex[1] = indexY[0]; lastIndex[2] = indexZ[0]; } // compute the weights weight[0] = xyz1[0] * xyz1[1] * xyz1[2]; weight[1] = xyz0[0] * xyz1[1] * xyz1[2]; weight[2] = xyz0[0] * xyz0[1] * xyz1[2]; weight[3] = xyz0[0] * xyz1[1] * xyz0[2]; weight[4] = xyz0[0] * xyz0[1] * xyz0[2]; weight[5] = xyz1[0] * xyz0[1] * xyz1[2]; weight[6] = xyz1[0] * xyz1[1] * xyz0[2]; weight[7] = xyz1[0] * xyz0[1] * xyz0[2]; // sum up all weighted motions deform.SetNull(); for(int i=0;i<8;i++) { motionScl[i].Scale(weight[i],motion[i]); deform.AddInPlace(motionScl[i]); } // output the deformed position outData[it][k] = deform; } } } } break; // Other output ports... }; return CStatus::OK; }