void Builder::FinalizeAnyPolyline() { // Save the last polyline / polygon if one exists. if ( current_polyline_pointcount > 0 ) { if ( current_polyline_willclose ) { polyVertex << DL_VertexData( closePolyX, closePolyY, closePolyZ ); } int dim = polyVertex.size(); QVector<double> xv( dim ); QVector<double> yv( dim ); QVector<double> zv( dim ); for ( int i = 0; i < dim; i++ ) { xv[i] = polyVertex[i].x; yv[i] = polyVertex[i].y; zv[i] = polyVertex[i].z; } shpObjects << SHPCreateObject( shapefileType, shpObjects.size(), 0, NULL, NULL, dim, xv.data(), yv.data(), zv.data(), NULL ); polyVertex.clear(); QgsDebugMsg( QString( "Finalized adding of polyline shape %1" ).arg( shpObjects.size() - 1 ) ); current_polyline_pointcount = 0; } }
inline long double cyl_neumann(long double a, long double x) { #ifdef BOOST_MSVC return yv((double)a, x); #else return yvl(a, x); #endif }
double struve(double v, double x) { double y, ya, f, g, h, t; double onef2err, threef0err; f = floor(v); if ((v < 0) && (v - f == 0.5)) { y = jv(-v, x); f = 1.0 - f; g = 2.0 * floor(f / 2.0); if (g != f) y = -y; return(y); } t = 0.25 * x * x; f = fabs(x); g = 1.5 * fabs(v); if ((f > 30.0) && (f > g)) { onef2err = 1.0e38; y = 0.0; } else { y = onef2(1.0, 1.5, 1.5 + v, -t, &onef2err); } if ((f < 18.0) || (x < 0.0)) { threef0err = 1.0e38; ya = 0.0; } else { ya = threef0(1.0, 0.5, 0.5 - v, -1.0 / t, &threef0err); } f = sqrt(PI); h = pow(0.5 * x, v - 1.0); if (onef2err <= threef0err) { g = gam(v + 1.5); y = y * h * t / (0.5 * f * g); return(y); } else { g = gam(v + 0.5); ya = ya * h / (f * g); ya = ya + yv(v, x); return(ya); } }
void Builder::addCircle( const DL_CircleData& data ) { if ( shapefileType != SHPT_ARC && shapefileType != SHPT_POLYGON ) { QgsDebugMsg( "ignoring circle" ); return; } QgsDebugMsg( QString( "circle (%1,%2,%3 r=%4)" ).arg( data.cx ).arg( data.cy ).arg( data.cz ).arg( data.radius ) ); if ( ignoringBlock ) { QgsDebugMsg( "skipping circle in block" ); return; } std::vector <DL_PointData> circlePoints; DL_PointData myPoint; // Approximate the circle with 360 line segments connecting points along that circle long shpIndex = 0; for ( double i = 0.0; i <= 2*M_PI; i += M_PI / 180.0, shpIndex++ ) { myPoint.x = data.radius * cos( i ) + data.cx; myPoint.y = data.radius * sin( i ) + data.cy; myPoint.z = data.cz; circlePoints.push_back( myPoint ); } int dim = circlePoints.size(); QVector<double> xv( dim ); QVector<double> yv( dim ); QVector<double> zv( dim ); for ( int i = 0; i < dim; i++ ) { xv[i] = circlePoints[i].x; yv[i] = circlePoints[i].y; zv[i] = circlePoints[i].z; } shpObjects << SHPCreateObject( shapefileType, shpObjects.size(), 0, NULL, NULL, dim, xv.data(), yv.data(), zv.data(), NULL ); circlePoints.clear(); }
void moto_setVarVal(MotoEnv *env, MotoVar *var, MotoVal *val) { moto_castVal(env,var->vs,val); /* If the MotoVar is a member var then we need to set the var in the MCI which this var is a member of */ if(var->isMemberVar) { switch (var->type->kind) { case INT32_TYPE: *(int32_t*)var->address = iv(var->vs); break; case INT64_TYPE: *(int64_t*)var->address = lv(var->vs); break; case FLOAT_TYPE: *(float*)var->address = fv(var->vs); break; case DOUBLE_TYPE: *(double*)var->address = dv(var->vs); break; case BOOLEAN_TYPE: *(unsigned char*)var->address = bv(var->vs); break; case BYTE_TYPE: *(signed char*)var->address = yv(var->vs); break; case CHAR_TYPE: *(char*)var->address = cv(var->vs); break; case REF_TYPE: *(void**)var->address = var->vs->refval.value; break; default: break; } } }
void Builder::addArc( const DL_ArcData& data ) { if ( shapefileType != SHPT_ARC ) { QgsDebugMsg( "ignoring arc" ); return; } int fromAngle = ( int ) data.angle1 + 1; int toAngle = ( int ) data.angle2 + 1; QgsDebugMsg( QString( "arc (%1,%2,%3 r=%4 a1=%5 a2=%6)" ) .arg( data.cx ).arg( data.cy ).arg( data.cz ) .arg( data.radius ) .arg( data.angle1 ).arg( data.angle2 ) ); if ( ignoringBlock ) { QgsDebugMsg( "skipping arc in block" ); return; } int i = 0; long shpIndex = 0; // Approximate the arc double radianMeasure; std::vector <DL_PointData> arcPoints; DL_PointData myPoint; for ( i = fromAngle; ; i++, shpIndex++ ) { if ( i > 360 ) i = 0; if ( shpIndex > 1000 ) break; radianMeasure = i * M_PI / 180.0; myPoint.x = data.radius * cos( radianMeasure ) + data.cx; myPoint.y = data.radius * sin( radianMeasure ) + data.cy; myPoint.z = data.cz; arcPoints.push_back( myPoint ); if ( i == toAngle ) break; } // Finalize int dim = arcPoints.size(); QVector<double> xv( dim ); QVector<double> yv( dim ); QVector<double> zv( dim ); for ( int i = 0; i < dim; i++ ) { xv[i] = arcPoints[i].x; yv[i] = arcPoints[i].y; zv[i] = arcPoints[i].z; } shpObjects << SHPCreateObject( shapefileType, shpObjects.size(), 0, NULL, NULL, dim, xv.data(), yv.data(), zv.data(), NULL ); arcPoints.clear(); }
void Builder::addPolyline( const DL_PolylineData& data ) { if ( shapefileType != SHPT_ARC && shapefileType != SHPT_POLYGON ) { QgsDebugMsg( "ignoring polyline" ); return; } QgsDebugMsg( "reading polyline - expecting vertices" ); if ( ignoringBlock ) { QgsDebugMsg( "skipping polyline in block" ); return; } // Add previously created polyline if not finalized yet if ( current_polyline_pointcount > 0 ) { if ( current_polyline_willclose ) { DL_VertexData myVertex; myVertex.x = closePolyX; myVertex.y = closePolyY; myVertex.z = closePolyZ; polyVertex.push_back( myVertex ); } int dim = polyVertex.size(); QVector<double> xv( dim ); QVector<double> yv( dim ); QVector<double> zv( dim ); for ( int i = 0; i < dim; i++ ) { xv[i] = polyVertex[i].x; yv[i] = polyVertex[i].y; zv[i] = polyVertex[i].z; } shpObjects << SHPCreateObject( shapefileType, shpObjects.size(), 0, NULL, NULL, dim, xv.data(), yv.data(), zv.data(), NULL ); polyVertex.clear(); QgsDebugMsg( QString( "polyline prepared: %1" ).arg( shpObjects.size() - 1 ) ); current_polyline_pointcount = 0; } // Now that the currently-adding polyline (if any) is // finalized, parse out the flag options if ( data.flags == 1 || data.flags == 32 ) { current_polyline_willclose = true; store_next_vertex_for_polyline_close = true; } else { current_polyline_willclose = false; store_next_vertex_for_polyline_close = false; } current_polyline_pointcount = 0; }
void Framework::update(){ WindowCreator wc = WindowCreator::instance(); if ( gFirst ){ const char* filename = wc.commandLineString(); if ( filename && filename[ 0 ] != '\0' ){ load( filename ); } gFirst = false; }else{ //ドラッグアンドドロップを処理する int dropN = wc.droppedItemNumber(); if ( dropN > 0 ){ const char* filename = wc.droppedItem( 0 ); //0番以外無視 load( filename ); wc.clearDroppedItem(); //これを呼ぶとfilenameもこわれるので最後に。 } } //カメラ入力反映 Input::Manager im = Input::Manager::instance(); Input::Mouse mouse = im.mouse(); Input::Keyboard keyboard = im.keyboard(); if ( mouse.isOn( Input::Mouse::BUTTON_MIDDLE ) ){ Graphics::Manager().captureScreen( "capture.tga" ); } //ビュー行列を作ろう Vector3 eyePosition = gEyeTarget; eyePosition.z += gEyeDistance; Matrix34 rm; rm.setRotationY( gAngleY ); rm.rotateX( gAngleX ); Vector3 tv( 0.f, 0.f, 1.f ); rm.mul( &tv, tv ); eyePosition.setMadd( gEyeTarget, tv, gEyeDistance ); Matrix34 zrm; zrm.setRotationZ( gAngleZ ); Vector3 up( 0.f, 1.f, 0.f ); zrm.mul( &up, up ); Matrix34 vm; vm.setViewTransform( eyePosition, gEyeTarget, up ); if ( gContainer ){ float x = static_cast< float >( mouse.velocityX() ); float y = static_cast< float >( mouse.velocityY() ); if ( mouse.isOn( Input::Mouse::BUTTON_LEFT ) && mouse.isOn( Input::Mouse::BUTTON_RIGHT ) ){ //両ボタンでZ回転 gAngleZ -= 0.2f * x; gAngleZ -= 0.2f * y; }else if ( mouse.isOn( Input::Mouse::BUTTON_LEFT ) ){ //左ボタン回転 gAngleX -= 0.2f * y; if ( gAngleX > 89.9f ){ gAngleX = 89.9f; }else if ( gAngleX < -89.9f ){ gAngleX = -89.9f; } gAngleY -= 0.5f * x; }else if ( mouse.isOn( Input::Mouse::BUTTON_RIGHT ) ){ //右ボタン、注視点移動 Vector3 xv( vm.m00, vm.m01, vm.m02 ); xv *= x; Vector3 yv( vm.m10, vm.m11, vm.m12 ); yv *= y; gEyeTarget.madd( xv, -0.003f * gEyeDistance ); gEyeTarget.madd( yv, 0.003f * gEyeDistance ); } int w = mouse.wheel(); if ( w < 0 ){ gEyeDistance *= 0.9f; }else if ( w > 0 ){ gEyeDistance *= 1.1f; } } //透視変換行列 Matrix44 pm; pm.setPerspectiveTransform( 60.f, static_cast< float >( width() ), static_cast< float >( height() ), gEyeDistance * 0.01f, gEyeDistance * 10.f ); //次にPVを作る pm *= vm; if ( keyboard.isOn( 'G' ) ){ gAngleX = gAngleY = gAngleZ = 0.f; gEyeTarget = 0.f; } //ライトでもうごかそか Graphics::Manager gm = Graphics::Manager::instance(); gm.setProjectionViewMatrix( pm ); gm.setLightingMode( LIGHTING_PER_PIXEL ); gm.enableDepthTest( true ); gm.enableDepthWrite( true ); gm.setLightColor( 0, Vector3( 1.f, 1.f, 1.f ) ); //白 gm.setLightColor( 1, Vector3( 1.f, 0.7f, 0.7f ) ); //赤 gm.setLightColor( 2, Vector3( 0.7f, 1.f, 0.7f ) ); //緑 gm.setLightColor( 3, Vector3( 0.7f, 0.7f, 1.f ) ); //青 gm.setAmbientColor( Vector3( 0.2f, 0.2f, 0.2f ) ); gm.setEyePosition( eyePosition ); float t = gEyeDistance * 0.4f; float lightIntensity[ 4 ]; for ( int i = 0; i < 4; ++i ){ lightIntensity[ i ] = t; } Vector3 lightPositions[ 4 ]; for ( int i = 0; i < 4; ++i ){ float t = static_cast< float >( gCount * ( i + 1 ) ) / 5.f; float d = gEyeDistance * 2.f; lightPositions[ i ].set( sin( t )*cos( t ) * d, sin( t )*sin( t ) * d, cos( t ) * d ); lightPositions[ i ] += gEyeTarget; } for ( int i = 0; i < 4; ++i ){ gm.setLightPosition( i, lightPositions[ i ] ); gm.setLightIntensity( i, lightIntensity[ i ] ); } for ( int i = 0; i < gModels.size(); ++i ){ gModels[ i ].draw(); } //アニメ切り替え if ( keyboard.isTriggered( ' ' ) ){ if ( gContainer.animationNumber() > 0 ){ ++gAnimationIndex; if ( gAnimationIndex >= gContainer.animationNumber() ){ gAnimationIndex = 0; } for ( int i = 0; i < gTrees.size(); ++i ){ gTrees[ i ].setAnimation( gContainer.animation( gAnimationIndex ) ); } } } for ( int i = 0; i < gTrees.size(); ++i ){ gTrees[ i ].updateAnimation(); gTrees[ i ].draw(); } if ( isEndRequested() ){ gModels.clear(); gTrees.clear(); gContainer.release(); } ++gCount; }
inline double cyl_neumann(double a, double x) { return yv(a, x); }
void multibinpacking(Home home, int n, int m, int k, const IntVarArgs& y, const IntVarArgs& x, const IntSharedArray& D, const IntSharedArray& B, IntConLevel) { /// Check input sizes if (n*k != D.size() ) throw ArgumentSizeMismatch("Int::multibinpacking"); if (k != B.size() ) throw ArgumentSizeMismatch("Int::multibinpacking"); if (n != x.size() ) throw ArgumentSizeMismatch("Int::multibinpacking"); if (m*k != y.size() ) throw ArgumentSizeMismatch("Int::multibinpacking"); for (int i=B.size(); i--; ) Limits::nonnegative(B[i],"Int::multibinpacking"); if (home.failed()) return; /// Post first each single binpacking constraint /// Capacity constraint for each dimension for ( int j = 0; j < m; ++j ) for ( int l = 0; l < k; ++l ) { IntView yi(y[j*k+l]); GECODE_ME_FAIL(yi.lq(home,B[l])); } /// Post a binpacking constraints for each dimension for ( int l = 0; l < k; ++l ) { ViewArray<OffsetView> yv(home,m); for (int j=m; j--; ) yv[j] = OffsetView(y[j*k+l],0); ViewArray<BinPacking::Item> xs(home,x.size()); for (int i=xs.size(); i--; ) xs[i] = BinPacking::Item(x[i],D[i*k+l]); Support::quicksort(&xs[0], xs.size()); GECODE_ES_FAIL(Int::BinPacking::Pack::post(home,yv,xs)); } /// Clique Finding and Alldifferent posting { /// Firt construct the conflict graph graph_t* g = graph_new(n); for ( int a = 0; a < n-1; ++a ) { for ( int b = a+1; b < n; ++b ) { int v = a; /// The variable with smaller domain int w = b; unsigned int nl = 0; if ( x[a].size() > x[b].size() ) { v = b; w = a; } IntVarValues i(x[v]); IntVarValues j(x[w]); while ( i() ) { if ( i.val() != j.val() ) { if ( i.val() < j.val() ) break; else ++i; } else { for ( int l = 0; l < k; ++l ) if ( D[a*k+l] + D[b*k+l] > B[l] ) { nl++; break; } ++i; ++j; } } if ( nl >= x[v].size() ) GRAPH_ADD_EDGE(g,a,b); } } /// Consitency cheking: look for the maximum clique clique_options* opts; opts = (clique_options*) malloc (sizeof(clique_options)); opts->time_function=NULL; opts->reorder_function=reorder_by_default; opts->reorder_map=NULL; opts->user_function=NULL; opts->user_data=NULL; opts->clique_list=NULL; opts->clique_list_length=0; set_t s; s = clique_find_single ( g, 0, 0, TRUE, opts); if ( s != NULL ) { if ( set_size(s) > m ) { set_free(s); free(opts); graph_free(g); GECODE_ES_FAIL(ES_FAILED); } if ( true ) { //option == 1 ) { FIXING for ( int a = 0, j = 0; a < n; ++a ) { if ( SET_CONTAINS_FAST(s,a) ) { assert( x[a].in(j) ); IntView xi(x[a]); GECODE_ME_FAIL(xi.eq(home,j++)); } } } } if ( s!=NULL ) set_free(s); /// List every maximal clique in the conflict graph opts->user_function=record_clique_func; clique_find_all ( g, 2, 0, TRUE, opts); for ( int c = 0; c < clique_count; c++ ) { ViewArray<IntView> xv(home, set_size(clique_list[c])); for ( int a = 0, idx = 0; a < n; ++a ) if ( SET_CONTAINS_FAST(clique_list[c],a) ) xv[idx++] = x[a]; GECODE_ES_FAIL(Distinct::Dom<IntView>::post(home,xv)); set_free(clique_list[c]); } free(opts); graph_free(g); } }
void doFrame(int fNum, char *fName) { RiFrameBegin(fNum); static RtColor Color = {.2, .4, .6} ; char buffer[256]; sprintf(buffer, "images/%s%03d.tif", fName, fNum); RiDisplay(buffer,(char*)"file",(char*)"rgba",RI_NULL); RiFormat(800, 600, 1.25); RiLightSource((char*)"distantlight",RI_NULL); RiProjection((char*)"perspective",RI_NULL); RiTranslate(0.0,0.0,50); // RiRotate(-40.0, 1.0,0.0,0.0); // RiRotate(-20.0, 0.0,1.0,0.0); RiWorldBegin(); RiColor(Color); RiRotate(fNum, 0.0,1.0,0.0); RtFloat roughness = 0.03; int trace = 1; //RtFloat km = .3; //RtFloat maxKm = 1.0; RtFloat opac[] = {0.5, 0.9, 0.3}; // RiBasis(RiBezierBasis, 3, RiBezierBasis, 3); //km = abs(sin(2.0*PI*((double)fNum/100.0))); // RiSurface((char*)"funkyglass", "roughness", (RtPointer)&roughness, RI_NULL); // RiOpacity(opac); // RiAttribute((char*)"visibility", "int trace", &trace, RI_NULL); RiSurface((char*)"matte", RI_NULL); RiSolidBegin("difference"); // RiTranslate(15,0,0); // RiSolidBegin("primitive"); // RiSphere(10, -10, 10, 360, RI_NULL); // RiSolidEnd(); double t=-PI; int steps = 8; double dt = (2*PI)/steps; RiSolidBegin("primitive"); double rad=5.0; for (int ti=0; ti<steps; ++ti) { RiTransformBegin(); RiTranslate(xv(t),yv(t),0); // RiSolidBegin("primitive"); RiSphere(rad, -rad, rad, 360, RI_NULL); // RiSolidEnd(); RiTransformEnd(); t += dt; } for (int ti=0; ti<steps; ++ti) { RiTransformBegin(); RiTranslate(0,xv(t),yv(t)); // RiSolidBegin("primitive"); RiSphere(rad, -rad, rad, 360, RI_NULL); // RiSolidEnd(); RiTransformEnd(); t += dt; } RiSolidEnd(); RiSolidBegin("primitive"); RiSphere(15, -15, 15, 360, RI_NULL); RiSolidEnd(); // RiTranslate(-30.0,-30.0,0); // RiSolidBegin("primitive"); // RiSphere(10, -10, 10, 360, RI_NULL); // RiSolidEnd(); // RiTranslate(15.0,-15.0,0); // RiSolidBegin("primitive"); // RiSphere(15, -15, 15, 360, RI_NULL); // RiSolidEnd(); RiSolidEnd(); RiWorldEnd(); RiFrameEnd(); }
void magnet::math::Spline::generate() { if (size() < 2) throw std::runtime_error("Spline requires at least 2 points"); // If any spline points are at the same x location, we have to // just slightly seperate them { bool testPassed(false); while (!testPassed) { testPassed = true; std::sort(base::begin(), base::end()); for (auto iPtr = base::begin(); iPtr != base::end() - 1; ++iPtr) if (iPtr->first == (iPtr + 1)->first) { if ((iPtr + 1)->first != 0) (iPtr + 1)->first += (iPtr + 1)->first * std::numeric_limits <double>::epsilon() * 10; else (iPtr + 1)->first = std::numeric_limits <double>::epsilon() * 10; testPassed = false; break; } } } const size_t e = size() - 1; switch (_type) { case LINEAR: { _data.resize(e); for (size_t i(0); i < e; ++i) { _data[i].x = x(i); _data[i].a = 0; _data[i].b = 0; _data[i].c = (y(i + 1) - y(i)) / (x(i + 1) - x(i)); _data[i].d = y(i); } break; } case CUBIC: { ublas::matrix<double> A(size(), size()); for (size_t yv(0); yv <= e; ++yv) for (size_t xv(0); xv <= e; ++xv) A(xv, yv) = 0; for (size_t i(1); i < e; ++i) { A(i - 1, i) = h(i - 1); A(i, i) = 2 * (h(i - 1) + h(i)); A(i + 1, i) = h(i); } ublas::vector<double> C(size()); for (size_t xv(0); xv <= e; ++xv) C(xv) = 0; for (size_t i(1); i < e; ++i) C(i) = 6 * ((y(i + 1) - y(i)) / h(i) - (y(i) - y(i - 1)) / h(i - 1)); // Boundary conditions switch (_BCLow) { case FIXED_1ST_DERIV_BC: C(0) = 6 * ((y(1) - y(0)) / h(0) - _BCLowVal); A(0, 0) = 2 * h(0); A(1, 0) = h(0); break; case FIXED_2ND_DERIV_BC: C(0) = _BCLowVal; A(0, 0) = 1; break; case PARABOLIC_RUNOUT_BC: C(0) = 0; A(0, 0) = 1; A(1, 0) = -1; break; } switch (_BCHigh) { case FIXED_1ST_DERIV_BC: C(e) = 6 * (_BCHighVal - (y(e) - y(e - 1)) / h(e - 1)); A(e, e) = 2 * h(e - 1); A(e - 1, e) = h(e - 1); break; case FIXED_2ND_DERIV_BC: C(e) = _BCHighVal; A(e, e) = 1; break; case PARABOLIC_RUNOUT_BC: C(e) = 0; A(e, e) = 1; A(e - 1, e) = -1; break; } ublas::matrix<double> AInv(size(), size()); InvertMatrix(A, AInv); _ddy = ublas::prod(C, AInv); _data.resize(size() - 1); for (size_t i(0); i < e; ++i) { _data[i].x = x(i); _data[i].a = (_ddy(i + 1) - _ddy(i)) / (6 * h(i)); _data[i].b = _ddy(i) / 2; _data[i].c = (y(i + 1) - y(i)) / h(i) - _ddy(i + 1) * h(i) / 6 - _ddy(i) * h(i) / 3; _data[i].d = y(i); } } } _valid = true; }
void SMDImporter::CreateAnimationSource() { XSI::ActionSource actionSource; float animStart = 9999; float animEnd = -9999; XSI::CString animatedObjects; for (int c=0;c<m_pNodes.GetUsed();c++) { SMDNode* node = m_pNodes[c]; if ( node->m_pKeys.GetUsed() > 1 ) { if ( !actionSource.IsValid() ) { LPWSTR l_wszActionName; DSA2W(&l_wszActionName,m_szActionName); actionSource = m_pModel.AddActionSource( l_wszActionName ); } XSI::Parameter x = node->m_x3d.GetParameters().GetItem( L"posx" ); XSI::Parameter y = node->m_x3d.GetParameters().GetItem( L"posy" ); XSI::Parameter z = node->m_x3d.GetParameters().GetItem( L"posz" ); XSI::Parameter rx = node->m_x3d.GetParameters().GetItem( L"rotx" ); XSI::Parameter ry = node->m_x3d.GetParameters().GetItem( L"roty" ); XSI::Parameter rz = node->m_x3d.GetParameters().GetItem( L"rotz" ); node->m_fOldX = x.GetValue(); node->m_fOldY = y.GetValue(); node->m_fOldZ = z.GetValue(); node->m_fOldRX = rx.GetValue(); node->m_fOldRY = ry.GetValue(); node->m_fOldRZ = rz.GetValue(); XSI::FCurve fcrvx; x.AddFCurve( XSI::siStandardFCurve, fcrvx ); XSI::FCurve fcrvy; y.AddFCurve( XSI::siStandardFCurve, fcrvy ); XSI::FCurve fcrvz; z.AddFCurve( XSI::siStandardFCurve, fcrvz ); XSI::FCurve fcrvrx; rx.AddFCurve( XSI::siStandardFCurve, fcrvrx ); XSI::FCurve fcrvry; ry.AddFCurve( XSI::siStandardFCurve, fcrvry ); XSI::FCurve fcrvrz; rz.AddFCurve( XSI::siStandardFCurve, fcrvrz ); XSI::CTimeArray time(node->m_pKeys.GetUsed()); XSI::CValueArray xv(node->m_pKeys.GetUsed()); XSI::CValueArray yv(node->m_pKeys.GetUsed()); XSI::CValueArray zv(node->m_pKeys.GetUsed()); XSI::CValueArray rxv(node->m_pKeys.GetUsed()); XSI::CValueArray ryv(node->m_pKeys.GetUsed()); XSI::CValueArray rzv(node->m_pKeys.GetUsed()); if ( node->m_pParent ==NULL ) { for (int k=0;k<node->m_pKeys.GetUsed();k++) { if ( node->GetKey(k)->m_fTime < animStart ) { animStart = node->GetKey(k)->m_fTime; } if ( node->GetKey(k)->m_fTime > animEnd ) { animEnd = node->GetKey(k)->m_fTime; } XSI::MATH::CTransformation xfo1; XSI::MATH::CTransformation xfo2; xfo1.SetRotationFromXYZAnglesValues ( node->GetKey(k)->m_vRotation.GetX(), node->GetKey(k)->m_vRotation.GetY(), node->GetKey(k)->m_vRotation.GetZ() ); xfo1.SetTranslationFromValues ( node->GetKey(k)->m_vPosition.GetX(), node->GetKey(k)->m_vPosition.GetY(), node->GetKey(k)->m_vPosition.GetZ() ); xfo2.SetRotationFromXYZAnglesValues ( -1.570796, 0.0, 0.0 ); xfo1.MulInPlace(xfo2); double dx,dy,dz; double drx, dry, drz; xfo1.GetTranslationValues ( dx, dy, dz); xfo1.GetRotationFromXYZAnglesValues(drx, dry, drz); time[k] = k; xv[k] = dx; yv[k] = dy; zv[k] = dz; rxv[k] = drx * 57.29577951308232286465; ryv[k] = dry * 57.29577951308232286465; rzv[k] = drz * 57.29577951308232286465; } } else { for (int k=0;k<node->m_pKeys.GetUsed();k++) { if ( node->GetKey(k)->m_fTime < animStart ) { animStart = node->GetKey(k)->m_fTime; } if ( node->GetKey(k)->m_fTime > animEnd ) { animEnd = node->GetKey(k)->m_fTime; } time[k] = k; xv[k] = node->GetKey(k)->m_vPosition.GetX(); yv[k] = node->GetKey(k)->m_vPosition.GetY(); zv[k] = node->GetKey(k)->m_vPosition.GetZ(); rxv[k] = node->GetKey(k)->m_vRotation.GetX() * 57.29577951308232286465; ryv[k] = node->GetKey(k)->m_vRotation.GetY() * 57.29577951308232286465; rzv[k] = node->GetKey(k)->m_vRotation.GetZ() * 57.29577951308232286465; } } fcrvx.SetKeys ( time, xv ); fcrvy.SetKeys ( time, yv ); fcrvz.SetKeys ( time, zv ); fcrvrx.SetKeys ( time, rxv ); fcrvry.SetKeys ( time, ryv ); fcrvrz.SetKeys ( time, rzv ); LPWSTR l_wszModelName; DSA2W(&l_wszModelName,FixName(node->m_szName)); XSI::CString cname = l_wszModelName; actionSource.AddSourceItem ( cname + L".kine.local.posx", fcrvx, true ); actionSource.AddSourceItem ( cname + L".kine.local.posy", fcrvy, true ); actionSource.AddSourceItem ( cname + L".kine.local.posz", fcrvz, true ); actionSource.AddSourceItem ( cname + L".kine.local.rotx", fcrvrx, true ); actionSource.AddSourceItem ( cname + L".kine.local.roty", fcrvry, true ); actionSource.AddSourceItem ( cname + L".kine.local.rotz", fcrvrz, true ); // build up the string list of objects that we want to remove animation from if (animatedObjects.IsEmpty() == false) { animatedObjects += L", "; } animatedObjects += node->m_x3d.GetFullName(); } } if ( actionSource.IsValid() ) { actionSource.PutParameterValue(L"FrameStart", (double)animStart); actionSource.PutParameterValue(L"FrameEnd", (double)animEnd); } // remove animation on all objects that were imported // and animated if (animatedObjects.IsEmpty() == false) { XSI::Application app; XSI::CValue out; XSI::CValueArray args(4); args[0] = animatedObjects; args[1] = XSI::CValue(); args[2] = (long)XSI::siBranch; args[3] = (long)(XSI::siFCurveSource); app.ExecuteCommand(L"RemoveAllAnimation", args, out); } }
void moto_castVal(MotoEnv *env, MotoVal *to, MotoVal *from) { switch (to->type->kind) { case BOOLEAN_TYPE: to->booleanval.value = from->booleanval.value; break; case BYTE_TYPE: switch (from->type->kind) { case BYTE_TYPE: to->byteval.value = yv(from); break; case CHAR_TYPE: to->byteval.value = cv(from); break; case INT32_TYPE: to->byteval.value = iv(from); break; case INT64_TYPE: to->byteval.value = lv(from); break; case FLOAT_TYPE: to->byteval.value = fv(from); break; case DOUBLE_TYPE: to->byteval.value = dv(from); break; default: THROW_D("MotoException"); break; } break; case CHAR_TYPE: switch (from->type->kind) { case BYTE_TYPE: to->charval.value = yv(from); break; case CHAR_TYPE: to->charval.value = cv(from); break; case INT32_TYPE: to->charval.value = iv(from); break; case INT64_TYPE: to->charval.value = lv(from); break; case FLOAT_TYPE: to->charval.value = fv(from); break; case DOUBLE_TYPE: to->charval.value = dv(from); break; default: THROW_D("MotoException"); break; } break; case INT32_TYPE: switch (from->type->kind) { case BYTE_TYPE: to->intval.value = yv(from); break; case CHAR_TYPE: to->intval.value = cv(from); break; case INT32_TYPE: to->intval.value = iv(from); break; case INT64_TYPE: to->intval.value = lv(from); break; case FLOAT_TYPE: to->intval.value = fv(from); break; case DOUBLE_TYPE: to->intval.value = dv(from); break; default: THROW_D("MotoException"); break; } break; case INT64_TYPE: switch (from->type->kind) { case BYTE_TYPE: to->longval.value = yv(from); break; case CHAR_TYPE: to->longval.value = cv(from); break; case INT32_TYPE: to->longval.value = iv(from); break; case INT64_TYPE: to->longval.value = lv(from); break; case FLOAT_TYPE: to->longval.value = fv(from); break; case DOUBLE_TYPE: to->longval.value = dv(from); break; default: THROW_D("MotoException"); break; } break; case FLOAT_TYPE: switch (from->type->kind) { case BYTE_TYPE: to->floatval.value = yv(from); break; case CHAR_TYPE: to->floatval.value = cv(from); break; case INT32_TYPE: to->floatval.value = iv(from); break; #ifdef CAST_INT64_TO_INT32_FIRST case INT64_TYPE: to->floatval.value = (int32_t)lv(from); break; #else case INT64_TYPE: to->floatval.value = lv(from); break; #endif case FLOAT_TYPE: to->floatval.value = fv(from); break; case DOUBLE_TYPE: to->floatval.value = dv(from); break; default: THROW_D("MotoException"); break; } break; case DOUBLE_TYPE: switch (from->type->kind) { case BYTE_TYPE: to->doubleval.value = yv(from); break; case CHAR_TYPE: to->doubleval.value = cv(from); break; case INT32_TYPE: to->doubleval.value = iv(from); break; case INT64_TYPE: to->doubleval.value = lv(from); break; case FLOAT_TYPE: to->doubleval.value = fv(from); break; case DOUBLE_TYPE: to->doubleval.value = dv(from); break; default: THROW_D("MotoException"); break; } break; case REF_TYPE: switch (from->type->kind) { case REF_TYPE: to->refval.value = from->refval.value; /* This causes big problems when assigning to a variable */ /* to->refval.subtype = from->refval.subtype; to->refval.dim = from->refval.dim; */ break; default: THROW_D("MotoException"); break; } break; default: THROW_D("MotoException"); break; } }