void MyTexturedBox::init() { _physics.setPosition(3,1.01,3); _physics.setAngularVelocity(10.0); makeMaterial(); makeTexture(); makeModel(); }
void MyBox::init() { _physics.setPosition(3,1.01,-3); _physics.setAngularVelocity(1000); //considerar sizeOfBlock/2 em x de 10 _physics.setLinearVelocity(100); //_lastposition = _physics.getPosition(); Remove makeModel(); }
void Key::init() { _physics.setPosition(0,1.0,-6); //_physics.setAngularVelocity(20.0); makeQuadric(); makeModel(); makeFront(); //makeMaterial(); }
void Wall::setModel ( const glm::vec3& trans, const glm::vec3& rot, const glm::vec3& scale ) { _model = makeModel ( trans, rot, scale ); btTransform t; t.setIdentity(); t.setOrigin ( glm2bt ( trans ) ); if ( glm::dot ( rot, rot ) > 0.01 ) { t.setRotation ( btQuaternion ( glm2bt ( glm::normalize ( rot ) ), glm::length ( rot ) ) ); } _body->setCenterOfMassTransform ( t ); Engine::BoxShapeManager->release ( _shape ); _shape = Engine::BoxShapeManager->request ( scale ); _body->setCollisionShape ( _shape ); }
void MyWorld::init() { _n = 100; _size.set(10.0,10.0); makeModel(); makeMaterial(); }
SEXP random_ferns(SEXP sAttributes,SEXP sDecision,SEXP sD,SEXP sNumFerns,SEXP sCalcImp,SEXP sOobErrEvery,SEXP sHoldForest,SEXP sMultilabel,SEXP sConsSeed){ struct attribute *X; uint nAtt,nObj,nClass,*Y; uint multi=INTEGER(sMultilabel)[0]; loadAttributes(sAttributes,&X,&nAtt,&nObj); if(!multi){ nClass=length(getAttrib(sDecision,R_LevelsSymbol)); //Sadly, we need to copy Y=(uint*)R_alloc(sizeof(uint),nObj); for(uint e=0;e<nObj;e++) Y[e]=INTEGER(sDecision)[e]-1; }else{ nClass=length(sDecision)/nObj; Y=(uint*)R_alloc(sizeof(uint),nObj*nClass); for(uint e=0;e<nObj*nClass;e++) Y[e]=LOGICAL(sDecision)[e]; } //Now, let's make the RNG and seed from R's RNG EMERGE_R_FROM_R; //Data loaded, time to load parameters params Q; Q.numClasses=nClass; Q.D=INTEGER(sD)[0]; Q.twoToD=1<<(Q.D); Q.numFerns=INTEGER(sNumFerns)[0]; Q.repOobErrEvery=abs(INTEGER(sOobErrEvery)[0]); Q.holdOobErr=INTEGER(sOobErrEvery)[0]>0; Q.calcImp=INTEGER(sCalcImp)[0]; //0->none, 1->msl, 2->msl+sha Q.holdForest=INTEGER(sHoldForest)[0]; Q.multilabel=multi; if(Q.calcImp==2){ Q.consSeed=((uint64_t*)INTEGER(sConsSeed))[0]; }else{ Q.consSeed=0; } //Start composing answer SEXP sAns; PROTECT(sAns=allocVector(VECSXP,5)); //Allocating fern forest; the whole space is controlled by R ferns ferns; SEXP sfSplitAtts=R_NilValue; SEXP sfScores=R_NilValue; if(Q.holdForest){ //To store the forest, we allocate vectors which will contain it // and build ferns out of their buffers. The rest is in saving forest. PROTECT(sfSplitAtts=allocVector(INTSXP,(Q.D)*(Q.numFerns))); ferns.splitAtts=INTEGER(sfSplitAtts); ferns.thresholds=(thresh*)R_alloc(sizeof(thresh),(Q.D)*(Q.numFerns)); PROTECT(sfScores=allocVector(REALSXP,(Q.twoToD)*(Q.numClasses)*(Q.numFerns))); ferns.scores=(score_t*)REAL(sfScores); }else{ //In the opposite case, we allocate a chunk for 1-fern forest on GC heap ferns.splitAtts=(int*)R_alloc(Q.D,sizeof(int)); ferns.thresholds=(thresh*)R_alloc(Q.D,sizeof(thresh)); ferns.scores=(double*)R_alloc((Q.numClasses)*(Q.twoToD),sizeof(double)); } //Fire the code model *M=makeModel(X,nAtt,Y,nObj,&ferns,&Q,_R); //Saving forest if(Q.holdForest){ SEXP sfThreReal; PROTECT(sfThreReal=allocVector(REALSXP,(Q.D)*(Q.numFerns))); SEXP sfThreInt; PROTECT(sfThreInt=allocVector(INTSXP,(Q.D)*(Q.numFerns))); for(uint e=0;e<(Q.D)*(Q.numFerns);e++){ if(X[ferns.splitAtts[e]].numCat!=0){ INTEGER(sfThreInt)[e]=ferns.thresholds[e].selection; REAL(sfThreReal)[e]=NAN; }else{ INTEGER(sfThreInt)[e]=-1; REAL(sfThreReal)[e]=ferns.thresholds[e].value; } } SEXP sModel; PROTECT(sModel=allocVector(VECSXP,4)); SET_VECTOR_ELT(sModel,0,sfSplitAtts); SET_VECTOR_ELT(sModel,1,sfThreReal); SET_VECTOR_ELT(sModel,2,sfThreInt); SET_VECTOR_ELT(sModel,3,sfScores); SEXP sModelNames; PROTECT(sModelNames=NEW_CHARACTER(4)); SET_STRING_ELT(sModelNames,0,mkChar("splitAttIdxs")); SET_STRING_ELT(sModelNames,1,mkChar("threReal")); SET_STRING_ELT(sModelNames,2,mkChar("threInteger")); SET_STRING_ELT(sModelNames,3,mkChar("scores")); setAttrib(sModel,R_NamesSymbol,sModelNames); SET_VECTOR_ELT(sAns,0,sModel); UNPROTECT(6); //UPs: sModelNames, sModel, sfThreInt, sfThreReal, sfSplitAtts, sfScores //Left: sAns }else{ SET_VECTOR_ELT(sAns,0,R_NilValue); } //Currently it always happens if(M->oobPreds){ //Build score matrix for R, with NAs for object which were never OOB SEXP sOobScores; PROTECT(sOobScores=allocVector(REALSXP,(Q.numClasses)*nObj)); SEXP sOobDim; PROTECT(sOobDim=allocVector(INTSXP,2)); INTEGER(sOobDim)[0]=Q.numClasses; INTEGER(sOobDim)[1]=nObj; double *tmp=REAL(sOobScores); for(uint e=0;e<nObj;e++) if(M->oobOutOfBagC[e]) for(uint ee=0;ee<Q.numClasses;ee++) tmp[e*Q.numClasses+ee]=M->oobPreds[e*Q.numClasses+ee]; else for(uint ee=0;ee<Q.numClasses;ee++) tmp[e*Q.numClasses+ee]=NA_REAL; setAttrib(sOobScores,R_DimSymbol,sOobDim); SET_VECTOR_ELT(sAns,1,sOobScores); UNPROTECT(2); //UPs: sOobScores, sOobDim //Left: sAns if(!multi){ //Do actual voting on this matrix; push NA for never-oobs and //random-of-max for ties. SEXP sOobPreds; PROTECT(sOobPreds=allocVector(INTSXP,nObj)); sint *winningClass=INTEGER(sOobPreds); for(uint e=0;e<nObj;e++) if(M->oobOutOfBagC[e]){ winningClass[e]=whichMaxTieAware(&(M->oobPreds[e*Q.numClasses]),Q.numClasses,_R); } else winningClass[e]=NA_INTEGER; SET_VECTOR_ELT(sAns,4,sOobPreds); UNPROTECT(1); //UPs: sOobPreds //Left: sAns }else{ SET_VECTOR_ELT(sAns,4,R_NilValue); } }else{ SET_VECTOR_ELT(sAns,1,R_NilValue); SET_VECTOR_ELT(sAns,4,R_NilValue); } if(M->oobErr){ SEXP sOobErr; PROTECT(sOobErr=allocVector(REALSXP,(Q.numFerns))); double *tmp=REAL(sOobErr); for(uint e=0;e<(Q.numFerns);e++) tmp[e]=M->oobErr[e]; SET_VECTOR_ELT(sAns,2,sOobErr); UNPROTECT(1); //UPs: sOobErr //Left: sAns }else{ SET_VECTOR_ELT(sAns,2,R_NilValue); } if(M->imp){ SEXP sImp; if(Q.calcImp==1){ PROTECT(sImp=allocVector(REALSXP,nAtt*2)); double *tmp=REAL(sImp); for(uint e=0;e<nAtt;e++) tmp[e]=M->imp[e]; for(uint e=0;e<nAtt;e++) tmp[e+nAtt]=M->try[e]; }else{ PROTECT(sImp=allocVector(REALSXP,nAtt*3)); double *tmp=REAL(sImp); for(uint e=0;e<nAtt;e++) tmp[e]=M->imp[e]; for(uint e=0;e<nAtt;e++) tmp[e+nAtt]=M->shimp[e]; for(uint e=0;e<nAtt;e++) tmp[e+nAtt*2]=M->try[e]; } SET_VECTOR_ELT(sAns,3,sImp); UNPROTECT(1); //UPs: sImp, one or another //Left: sAns }else{