Compound* Actor::createCompoundFromChunk(const destructible::DestructibleActorImpl& actor, uint32_t partIndex) { Mesh RTmesh; RTmesh.loadFromRenderMesh(*actor.getDestructibleAsset()->getRenderMeshAsset(),partIndex); // Fix texture v's (different between right hand and left hand) RTmesh.flipV(); PxTransform pose(actor.getChunkPose(partIndex)); pose.p = actor.getStructure()->getChunkWorldCentroid(actor.getChunk(partIndex)); Compound* c = createCompound(); c->createFromMesh(&RTmesh,pose,actor.getChunkLinearVelocity(partIndex),actor.getChunkAngularVelocity(partIndex),-1,actor.getScale()); const DestructibleActorParamNS::BehaviorGroup_Type& behaviorGroup = actor.getBehaviorGroup(partIndex); mMinRadius = behaviorGroup.damageSpread.minimumRadius; mRadiusMultiplier = behaviorGroup.damageSpread.radiusMultiplier; // attachment //const DestructibleActorParamNS::RuntimeFracture_Type& params = mActor->getParams()->destructibleParameters.runtimeFracture; DestructibleParameters& params = mActor->getDestructibleParameters(); mAttachmentFlags.posX |= params.rtFractureParameters.attachment.posX; mAttachmentFlags.negX |= params.rtFractureParameters.attachment.negX; mAttachmentFlags.posY |= params.rtFractureParameters.attachment.posY; mAttachmentFlags.negY |= params.rtFractureParameters.attachment.negY; mAttachmentFlags.posZ |= params.rtFractureParameters.attachment.posZ; mAttachmentFlags.negZ |= params.rtFractureParameters.attachment.negZ; attachBasedOnFlags(c); mRenderResourcesDirty = true; return c; }
/*--------------------------------------------------------------------------*/ int sci_glue(char * fname, unsigned long fname_len) { SciErr sciErr; int* piAddrl1 = NULL; long long* l1 = NULL; double* l2 = NULL; int* lind = NULL; long long* outindex = NULL; int numrow = 0, numcol = 0, n = 0, cx1 = 1; int *pObj = NULL; int i = 0; int iCompoundUID = 0; int iParentUID = 0; int iCurrentParentUID = 0; int* piCurrentParentUID = &iCurrentParentUID; int iObjUID = 0; CheckInputArgument(pvApiCtx, 1, 1); CheckOutputArgument(pvApiCtx, 0, 1); /* set or create a graphic window */ sciErr = getVarAddressFromPosition(pvApiCtx, 1, &piAddrl1); if (sciErr.iErr) { printError(&sciErr, 0); return 1; } // Retrieve a matrix of handle at position 1. sciErr = getMatrixOfHandle(pvApiCtx, piAddrl1, &numrow, &numcol, &l1); /* We get the scalar value if it is ones */ if (sciErr.iErr) { printError(&sciErr, 0); Scierror(202, _("%s: Wrong type for input argument #%d: Handle matrix expected.\n"), fname, 1); return 1; } n = numrow * numcol; sciErr = allocMatrixOfDouble(pvApiCtx, nbInputArgument(pvApiCtx) + 1, numrow, numcol, &l2); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } sciErr = allocMatrixOfDoubleAsInteger(pvApiCtx, nbInputArgument(pvApiCtx) + 2, numrow, numcol, &lind); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } if (n > 1) { C2F(dcopy)(&n, (double*)l1, &cx1, l2, &cx1); C2F(dsort)(l2, &n, (int*)(lind)); for (i = 1; i < n; i++) { long long i1 = ((long long*)l2)[i]; long long i2 = ((long long*)l2)[i - 1]; if (i1 == i2) { Scierror(999, _("%s: Each handle should not appear twice.\n"), fname); return 0; } } } /* we must change the pobj to the Compound type */ pObj = (int*)MALLOC(n * sizeof(int)); for (i = 0 ; i < n ; i++) { iObjUID = getObjectFromHandle((long)l1[i]); pObj[i] = iObjUID; if (iObjUID == 0) { FREE(pObj); Scierror(999, _("%s: The handle is not or no more valid.\n"), fname); return 0; } iCurrentParentUID = getParentObject(iObjUID); //getGraphicObjectProperty(iObjUID, __GO_PARENT__, jni_string, (void **)&piCurrentParentUID); if (i == 0) { iParentUID = iCurrentParentUID; } if (iParentUID != iCurrentParentUID) { FREE(pObj); Scierror(999, _("%s: Objects must have the same parent.\n"), fname); return 0; } } //ret = CheckForCompound (handelsvalue, n); //if (ret>0) //{ // MEM LEAK // Scierror(999,_("%s: Handle %d cannot be glued (invalid parent).\n"),fname,ret); // return 0; //} //if (ret<0) //{ // MEM LEAK // Scierror(999,_("%s: Handle %d cannot be glued (invalid type).\n"),fname,-ret); // return 0; //} iCompoundUID = createCompound(iParentUID, pObj, n); setCurrentObject(iCompoundUID); numrow = 1; numcol = 1; sciErr = allocMatrixOfHandle(pvApiCtx, nbInputArgument(pvApiCtx) + 3, numrow, numcol, &outindex); if (sciErr.iErr) { printError(&sciErr, 0); Scierror(999, _("%s: Memory allocation error.\n"), fname); return 1; } outindex[0] = getHandle(iCompoundUID); AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 3; ReturnArguments(pvApiCtx); FREE(pObj); return 0; }
int plot2dn(int ptype, char *logflags, double *x, double *y, int *n1, int *n2, int *style, char *strflag, char *legend, double *brect, int *aaint, BOOL flagNax, int lstr1, int lstr2) { int iSubwinUID = 0; int iCurFigureUID = 0; int closeflag = 0; int jj = 0; long hdl = 0; int *pObj = NULL; int cmpt = 0; int with_leg = 0; double drect[6]; char dataflag = 0; BOOL bounds_changed = FALSE; BOOL axes_properties_changed = FALSE; double rotationAngles[2]; int clipState = 0; int autoScale = 0; int logFlags[3]; int iTmp = 0; int *piTmp = &iTmp; char textLogFlags[3]; int firstPlot = 0; int newFirstPlot = 0; int autoSubticks = 0; iSubwinUID = getOrCreateDefaultSubwin(); /* * Check if the auto_clear property is on and then erase everything * To be implemented */ checkRedrawing(); rotationAngles[0] = 0.0; rotationAngles[1] = 270.0; setGraphicObjectProperty(iSubwinUID, __GO_ROTATION_ANGLES__, rotationAngles, jni_double_vector, 2); /* Force logflags to those given by argument */ getGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, jni_bool, (void **)&piTmp); firstPlot = iTmp; /* Reset x and y logflags */ if (firstPlot) { logFlags[0] = getBooleanLogFlag(logflags[1]); logFlags[1] = getBooleanLogFlag(logflags[2]); setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, &logFlags[0], jni_bool, 1); setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, &logFlags[1], jni_bool, 1); } /* Forces "clipgrf" clipping (1) */ clipState = 1; setGraphicObjectProperty(iSubwinUID, __GO_CLIP_STATE__, &clipState, jni_int, 1); getGraphicObjectProperty(iSubwinUID, __GO_AUTO_SCALE__, jni_bool, (void **)&piTmp); autoScale = iTmp; if (autoScale) { /* compute and merge new specified bounds with the data bounds */ switch (strflag[1]) { case '0': /* do not change data bounds */ break; case '1': case '3': case '5': case '7': /* Force data bounds=brect */ re_index_brect(brect, drect); break; case '2': case '4': case '6': case '8': case '9': /* Force data bounds to the x and y bounds */ if ((int)strlen(logflags) < 1) { dataflag = 'g'; } else { dataflag = logflags[0]; } getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[0] = iTmp; getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[1] = iTmp; getGraphicObjectProperty(iSubwinUID, __GO_Z_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[2] = iTmp; /* Conversion required by compute_data_bounds2 */ textLogFlags[0] = getTextLogFlag(logFlags[0]); textLogFlags[1] = getTextLogFlag(logFlags[1]); textLogFlags[2] = getTextLogFlag(logFlags[2]); compute_data_bounds2(0, dataflag, textLogFlags, x, y, *n1, *n2, drect); break; } /* merge data bounds and drect */ if (!firstPlot && (strflag[1] == '5' || strflag[1] == '7' || strflag[1] == '8' || strflag[1] == '9')) { double *dataBounds; getGraphicObjectProperty(iSubwinUID, __GO_DATA_BOUNDS__, jni_double_vector, (void **)&dataBounds); drect[0] = Min(dataBounds[0], drect[0]); /*xmin */ drect[2] = Min(dataBounds[2], drect[2]); /*ymin */ drect[1] = Max(dataBounds[1], drect[1]); /*xmax */ drect[3] = Max(dataBounds[3], drect[3]); /*ymax */ } if (strflag[1] != '0') { bounds_changed = update_specification_bounds(iSubwinUID, drect, 2); } } if (firstPlot) { bounds_changed = TRUE; } /* Adapted to the MVC */ axes_properties_changed = strflag2axes_properties(iSubwinUID, strflag); /* just after strflag2axes_properties */ newFirstPlot = 0; setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &newFirstPlot, jni_bool, 1); with_leg = (strflag[0] == '1'); /* F.Leray 07.10.04 : trigger algo to init. manual graduation u_xgrads and * u_ygrads if nax (in matdes.c which is == aaint HERE) was specified */ /* The MVC AUTO_SUBTICKS property corresponds to !flagNax */ autoSubticks = !flagNax; setGraphicObjectProperty(iSubwinUID, __GO_AUTO_SUBTICKS__, &autoSubticks, jni_bool, 1); if (flagNax == TRUE) { getGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[0] = iTmp; getGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_LOG_FLAG__, jni_bool, (void **)&piTmp); logFlags[1] = iTmp; if (logFlags[0] == 0 && logFlags[1] == 0) { int autoTicks = 0; int i = 0; int iSize = 0; double dblFabs = 0; char** stringVector = NULL; if (aaint[1] == -1) { autoTicks = 1; setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); } else if (aaint[1] == 0) { setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0); autoTicks = 0; setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); } else { double* dXGrads = (double*) MALLOC(aaint[1] * sizeof(double)); // Compute X grads dXGrads[0] = drect[0]; if (aaint[1] > 1) { double pas = (drect[1] - drect[0]) / (aaint[1] - 1); for (i = 0; i < aaint[1]; i++) { dXGrads[i] = drect[0] + pas * i; } } autoTicks = 0; setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LOCATIONS__, dXGrads, jni_double_vector, aaint[1]); // Create X Labels stringVector = (char **) MALLOC(aaint[1] * sizeof(char*)); for (i = 0; i < aaint[1]; i++) { iSize = 6; if (dXGrads[i] < 0) { iSize += 2; } dblFabs = fabs(dXGrads[i]); if (dblFabs >= 10) { iSize = iSize + (int)floor(log10(dblFabs)); } stringVector[i] = (char*) MALLOC(iSize * sizeof(char)); sprintf(stringVector[i], "%.3f", dXGrads[i]); stringVector[i][iSize - 1] = '\0'; } setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[1]); for (i = 0; i < aaint[1]; i++) { FREE(stringVector[i]); } FREE(stringVector); FREE(dXGrads); stringVector = NULL; } if (aaint[3] == -1) { autoTicks = 1; setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); } else if (aaint[3] == 0) { setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, NULL, jni_double_vector, 0); autoTicks = 0; setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); } else { double* dYGrads = (double*) MALLOC(aaint[3] * sizeof(double)); // Compute Y grads dYGrads[0] = drect[2]; if (aaint[3] > 1) { double pas = (drect[3] - drect[2]) / (aaint[3] - 1); for (i = 0; i < aaint[3]; i++) { dYGrads[i] = drect[2] + pas * i; } } autoTicks = 0; setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_AUTO_TICKS__, &autoTicks, jni_bool, 1); setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LOCATIONS__, dYGrads, jni_double_vector, aaint[3]); // Create Y Labels stringVector = (char**) MALLOC(aaint[3] * sizeof(char*)); for (i = 0; i < aaint[3]; i++) { iSize = 6; if (dYGrads[i] < 0) { iSize += 2; } dblFabs = fabs(dYGrads[i]); if (dblFabs >= 10) { iSize = iSize + (int)floor(log10(dblFabs)); } stringVector[i] = (char*) MALLOC(iSize * sizeof(char)); sprintf(stringVector[i], "%.3f", dYGrads[i]); stringVector[i][iSize - 1] = '\0'; } setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_TICKS_LABELS__, stringVector, jni_string_vector, aaint[3]); for (i = 0; i < aaint[3]; i++) { FREE(stringVector[i]); } FREE(stringVector); FREE(dYGrads); stringVector = NULL; } // X and Y subticks setGraphicObjectProperty(iSubwinUID, __GO_X_AXIS_SUBTICKS__, aaint, jni_int, 1); setGraphicObjectProperty(iSubwinUID, __GO_Y_AXIS_SUBTICKS__, &aaint[2], jni_int, 1); } else { sciprint(_("Warning: Nax does not work with logarithmic scaling.\n")); } } /*---- Drawing the curves and the legends ----*/ if (*n1 != 0) { if ((pObj = (int*)MALLOC((*n1 + 1) * sizeof(int))) == NULL) { Scierror(999, _("%s: No more memory.\n"), "plot2d"); return -1; } /*A.Djalel 3D axes */ for (jj = 0; jj < *n1; jj++) { int iObjUID = 0; if (style[jj] > 0) { BOOL isline = TRUE; if (ptype == 3) { isline = FALSE; } iObjUID = ConstructPolyline(getCurrentSubWin(), &(x[jj * (*n2)]), &(y[jj * (*n2)]), PD0, closeflag, *n2, ptype, &style[jj], NULL, NULL, NULL, NULL, isline, FALSE, FALSE, FALSE); } else { int minusstyle = -style[jj]; iObjUID = ConstructPolyline(getCurrentSubWin(), &(x[jj * (*n2)]), &(y[jj * (*n2)]), PD0, closeflag, *n2, ptype, NULL, NULL, &minusstyle, NULL, NULL, FALSE, FALSE, TRUE, FALSE); } if (iObjUID == 0) { // skip Scierror(999, _("%s: No more memory.\n"), "plot2d"); } else { setCurrentObject(iObjUID); pObj[cmpt] = iObjUID; cmpt++; } } /*---- Drawing the Legends ----*/ if (with_leg) { int iLegUID = 0; char **Str; int nleg; if (scitokenize(legend, &Str, &nleg)) { FREE(pObj); Scierror(999, _("%s: No more memory.\n"), "plot2d"); return 0; } iLegUID = ConstructLegend(getCurrentSubWin(), Str, pObj, Min(nleg, cmpt)); if (iLegUID != 0) { int legendLocation; int contourMode; /* 9: LOWER_CAPTION */ legendLocation = 9; setGraphicObjectProperty(iLegUID, __GO_LEGEND_LOCATION__, &legendLocation, jni_int, 1); contourMode = 0; setGraphicObjectProperty(iLegUID, __GO_FILL_MODE__, &contourMode, jni_bool, 1); setGraphicObjectProperty(iLegUID, __GO_LINE_MODE__, &contourMode, jni_bool, 1); } freeArrayOfString(Str, nleg); } /*---- construct Compound ----*/ if (cmpt > 0) { int parentVisible = 0; int *piParentVisible = &parentVisible; int iCompoundUID = createCompound(iSubwinUID, pObj, cmpt); setCurrentObject(iCompoundUID); } FREE(pObj); } /* End of the curves and legend block */ return 0; }
/*------------------------------------------------ * plot3d *-----------------------------------------------*/ void Objplot3d (char * fname , int * isfac , int * izcol , double x[] , double y[] , double z[] , double * zcol , int * m , int * n , double * theta , double * alpha , char * legend, int * iflag , double * ebox , int * m1 , /*Adding F.Leray 12.03.04 and 19.03.04*/ int * n1 , int * m2 , int * n2 , int * m3 , int * n3 , int * m3n , int * n3n) /* F.Leray 25.04.05 : warning here legends means "X@Y@Z": it is labels writings!! */ /* legends has not the same meaning than inside plot2dn (there, it is really the legends of the plotted curves)*/ { sciTypeOf3D typeof3d; int flagcolor = 0; int* pObj = NULL; int i = 0; int iSubwinUID = 0; int firstPlot = 0; int clipState = 0; int iNewSurfaceUID = 0; /* ================================================= * Force SubWindow properties according to arguments * ================================================= */ iSubwinUID = getCurrentSubWin(); checkRedrawing(); initSubWinTo3d(iSubwinUID, legend, iflag, *alpha, *theta, ebox, x, *m1 **n1, y, *m2 **n2, z, *m3 **n3); /* ================================================= * Analyze arguments to find entity type * ================================================= */ if (*isfac == 1) { if (*izcol == 0) { if (strcmp(fname, "plot3d1") == 0) { typeof3d = SCI_FAC3D; flagcolor = 1; } else { typeof3d = SCI_FAC3D; flagcolor = 0; } } else if (*izcol == 2) { typeof3d = SCI_FAC3D; flagcolor = 3; } else { typeof3d = SCI_FAC3D; flagcolor = 2; } } else if (*isfac == 0) { if (strcmp(fname, "plot3d1") == 0) { typeof3d = SCI_PLOT3D; flagcolor = 1; } else { typeof3d = SCI_PLOT3D; flagcolor = 0; } } else { typeof3d = SCI_PARAM3D1; flagcolor = 1; } /* ================================================= * Construct the Entities * ================================================= */ /*Distinction here between SCI_PARAM3D1 and others*/ if (typeof3d != SCI_PARAM3D1) { int dimvectx = -1; int dimvecty = -1; if (*isfac == 1) { /* x is considered as a matrix */ dimvectx = -1; } else if (*m1 == 1) /* x is a row vector */ { dimvectx = *n1; } else if (*n1 == 1) /* x is a column vector */ { dimvectx = *m1; } else /* x is a matrix */ { dimvectx = -1; } if (dimvectx > 1) { int monotony = checkMonotony(x, dimvectx); if (monotony == 0) { Scierror(999, _("%s: x vector is not monotonous.\n"), "Objplot3d"); return; } } if (*isfac == 1) { /* y is considered as a matrix */ dimvecty = -1; } else if (*m2 == 1) /* y is a row vector */ { dimvecty = *n2; } else if (*n2 == 1) /* y is a column vector */ { dimvecty = *m2; } else /* y is a matrix */ { dimvecty = -1; } if (dimvecty > 1) { /* test the monotony on y*/ int monotony = checkMonotony(y, dimvecty); if (monotony == 0) { Scierror(999, _("%s: y vector is not monotonous.\n"), "Objplot3d"); return; } } iNewSurfaceUID = ConstructSurface(iSubwinUID, typeof3d, x, y, z, zcol, *izcol, *m, *n, iflag, ebox, flagcolor, isfac, m1, n1, m2, n2, m3, n3, m3n, n3n); if (iNewSurfaceUID == 0) { Scierror(999, _("%s: No more memory.\n"), "Objplot3d"); return; } setCurrentObject(iNewSurfaceUID); /* Force clipping, 1: CLIPGRF */ clipState = 1; setGraphicObjectProperty(iNewSurfaceUID, __GO_CLIP_STATE__, &clipState, jni_int, 1); } else { int iNewPolylineUID = 0; int iCurrentSubwinUID = 0; if ((pObj = (int*)MALLOC (*n * sizeof (int))) == NULL) { Scierror(999, "%s: No more memory.\n", fname); return; } iCurrentSubwinUID = getCurrentSubWin(); for (i = 0; i < *n; ++i) { if ((*n > 0) && (zcol != (double *)NULL)) { if ((int) zcol[i] > 0) { int intzcol = (int) zcol[i]; iNewPolylineUID = ConstructPolyline (iCurrentSubwinUID, &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1, &intzcol, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE); } else { int intzcol = (int) - zcol[i]; iNewPolylineUID = ConstructPolyline (iCurrentSubwinUID, &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1, NULL, NULL, &intzcol, NULL, NULL, FALSE, FALSE, TRUE, FALSE); } } else { /* default case, nothing is given */ int curcolor = 0; int *piCurColor = &curcolor; getGraphicObjectProperty(iCurrentSubwinUID, __GO_LINE_COLOR__, jni_int, (void**)&piCurColor); iNewPolylineUID = ConstructPolyline(iCurrentSubwinUID, &(x[*m * i]), &(y[*m * i]), &(z[*m * i]), 0, *m, 1, &curcolor, NULL, NULL, NULL, NULL, TRUE, FALSE, FALSE, FALSE); } if (iNewPolylineUID == 0) { Scierror(999, _("%s: No more memory.\n"), fname); FREE(pObj); return; } setCurrentObject(iNewPolylineUID); setGraphicObjectRelationship(iCurrentSubwinUID, iNewPolylineUID); /* Force clipping, 1: CLIPGRF */ clipState = 1; setGraphicObjectProperty(iNewPolylineUID, __GO_CLIP_STATE__, &clipState, jni_int, 1); pObj[i] = iNewPolylineUID; } /** construct Compound and make it current object**/ if (*n > 1) { int o = createCompound (iCurrentSubwinUID, pObj, *n); setCurrentObject(o); } FREE(pObj); } /* ================================================= * Redraw Figure * ================================================= */ // subwin has been modified firstPlot = 0; setGraphicObjectProperty(iSubwinUID, __GO_FIRST_PLOT__, &firstPlot, jni_bool, 1); }
iPhysicsCollision* iPhysics::createCompound(vector<iPhysicsCollision*>& collisions) { return createCompound(collisions, _shadowWorldID); }