osg::Quat KeyframeController::getXYZRotation(float time) const { float xrot = 0, yrot = 0, zrot = 0; if (!mXRotations.empty()) xrot = mXRotations.interpKey(time); if (!mYRotations.empty()) yrot = mYRotations.interpKey(time); if (!mZRotations.empty()) zrot = mZRotations.interpKey(time); osg::Quat xr(xrot, osg::Vec3f(1,0,0)); osg::Quat yr(yrot, osg::Vec3f(0,1,0)); osg::Quat zr(zrot, osg::Vec3f(0,0,1)); return (xr*yr*zr); }
void SyntaxHighlightDlg::OnImport(wxCommandEvent& event) { wxString path = ::wxFileSelector(_("Select file"), "", "", "", "Zip Files (*.zip)|*.zip", wxFD_OPEN); if(path.IsEmpty()) return; wxFileName fn(path); clZipReader zr(fn); zr.Extract("*", clStandardPaths::Get().GetUserLexersDir()); // reload the settings ColoursAndFontsManager::Get().Reload(); EndModal(wxID_OK); // relaunch the dialog wxCommandEvent openEvent(wxEVT_COMMAND_MENU_SELECTED, XRCID("syntax_highlight")); clMainFrame::Get()->GetEventHandler()->AddPendingEvent(openEvent); }
I ea(I f,A a,A w) { A z,*p;I at,k,wt=0,j=0; C *ap,*wp=0; if(w)ND2 else ND1; at=a->t,k=a->r?Tt(at,1):0,ap=(C*)a->p; if(w) if(wt=w->t,wp=(C*)w->p,j=w->r?Tt(wt,1):0,k&&j) { Q(a->r!=w->r,7); Q(cm(a->d,w->d,a->r),8); } W(gd(Et,j?w:a)); *--Y=zr(z),p=(A*)z->p; DO(z->n, if(at<Et||(a=*(A*)ap,QF(a)))a=gc(at,0,1,0,(I*)ap); else ic(a);
void Camera::rotateCamera(const Ogre::Vector3 &rot, bool adjust) { if (adjust) { setYaw(getYaw() + rot.z); setPitch(getPitch() + rot.x); } else { setYaw(rot.z); setPitch(rot.x); } Ogre::Quaternion xr(Ogre::Radian(getPitch() + Ogre::Math::HALF_PI), Ogre::Vector3::UNIT_X); if (!mVanity.enabled && !mPreviewMode) { mCamera->getParentNode()->setOrientation(xr); } else { Ogre::Quaternion zr(Ogre::Radian(getYaw()), Ogre::Vector3::UNIT_Z); mCamera->getParentNode()->setOrientation(zr * xr); } }
void CSVRender::Object::adjustTransform() { if (mReferenceId.empty()) return; const CSMWorld::CellRef& reference = getReference(); // position mBaseNode->setPosition(mForceBaseToZero ? osg::Vec3() : osg::Vec3f(reference.mPos.pos[0], reference.mPos.pos[1], reference.mPos.pos[2])); // orientation osg::Quat xr (-reference.mPos.rot[0], osg::Vec3f(1,0,0)); osg::Quat yr (-reference.mPos.rot[1], osg::Vec3f(0,1,0)); osg::Quat zr (-reference.mPos.rot[2], osg::Vec3f(0,0,1)); mBaseNode->setAttitude(zr*yr*xr); mBaseNode->setScale(osg::Vec3(reference.mScale, reference.mScale, reference.mScale)); }
void AnnotationInterface::DynamicPaint( const View& v, VectorGraphics& g, const DRect& r ) const { // we need valid view and annotation must be placed if ( view == 0 || v != *view || !annotationPlaced ) return; // are we painting to rect with annotation? if ( !totalRect.Intersects( r ) ) return; // get the image window ImageWindow w = view->Window(); // render annotation to bitmap if needed if ( annotationBmp.IsNull() ) { relPosX = 0; relPosY = 0; annotationBmp = AnnotationRenderer::CreateAnnotationBitmap( instance, relPosX, relPosY, true ); screenBmp = Bitmap::Null(); } // compute viewport coordinates of annotation text int posX = instance.annotationPositionX - relPosX; int posY = instance.annotationPositionY - relPosY; w.ImageToViewport( posX, posY ); // compute zoom factor int zoomFactor = w.ZoomFactor(); double z = (zoomFactor < 0) ? -1.0/zoomFactor : double( zoomFactor ); // draw bitmap, scaled according to zoom factor Rect zr( RoundI( annotationBmp.Width()*z ), RoundI( annotationBmp.Height()*z ) ); if ( screenBmp.IsNull() || zr != screenBmp.Bounds() ) if ( zoomFactor < 0 ) screenBmp = annotationBmp.Scaled( z ); else screenBmp = annotationBmp; if ( zoomFactor < 0 ) g.DrawBitmap( posX, posY, screenBmp ); else g.DrawScaledBitmap( zr.MovedTo( posX, posY ), screenBmp ); }
void CSVRender::Object::adjustTransform() { if (mReferenceId.empty()) return; ESM::Position position = getPosition(); // position mRootNode->setPosition(mForceBaseToZero ? osg::Vec3() : osg::Vec3f(position.pos[0], position.pos[1], position.pos[2])); // orientation osg::Quat xr (-position.rot[0], osg::Vec3f(1,0,0)); osg::Quat yr (-position.rot[1], osg::Vec3f(0,1,0)); osg::Quat zr (-position.rot[2], osg::Vec3f(0,0,1)); mBaseNode->setAttitude(zr*yr*xr); float scale = getScale(); mBaseNode->setScale(osg::Vec3(scale, scale, scale)); }
std::vector<std::vector<Matrix> > RNN::FeedForward(Matrix input, int num_passes) { std::vector<std::vector<Matrix> > networkdata; Matrix prev_output; for (int i = 0; i < num_passes; i++) { if (i == 0) { std::vector<Matrix> zerorecurrence; for (int j = 0; j < Num_Layers; j++) { Matrix zr(InputVectorSize, 1); zerorecurrence.push_back(zr); } networkdata.push_back(PartialFeedFoward(input, zerorecurrence)); } else { networkdata.push_back(PartialFeedFoward(networkdata[networkdata.size() - 1][Num_Layers - 1], networkdata[networkdata.size() - 1])); } } return networkdata; }
// we use a tree architecture to build the subzones int VEF::divideIntoZones(Zone z, int nbZones){ TreeZone tz(z); TreeZone *father; int flag, flag2, depth; // used to determine the cutting axis flag = flag2 = depth = 0; Vertex bottom, middle_bottom, middle_top, top; bottom = middle_bottom = z.getZoneBottomVertex(); top = middle_top = z.getZoneTopVertex(); int id = 0; int rootFlag = 0; std::vector<TreeZone> parents; // store the parent trees relative to the one we manipulate for (int i = 0; i < nbZones; i++){ if (!(i % 2)){ if (flag % 3 == 0) // we cut along the x axis { Vertex vx(middle_top.getX() - (middle_top.getX() / 2), middle_top.getY(), middle_top.getZ()); Zone zl(bottom, vx, -1); TreeZone *l = new TreeZone(zl); tz.addLeftChild(l); //top.setX(vx.getX()); middle_top = vx; } if (flag % 3 == 1) // we cut along the y axis { Vertex vy(middle_top.getX(), middle_top.getY() - middle_top.getY() / 2, middle_top.getZ()); Zone zl(bottom, vy, -1); TreeZone *l = new TreeZone(zl); tz.addLeftChild(l); //top.setY(vy.getY()); middle_top = vy; } if (flag % 3 == 2) // we cut along the z axis { Vertex vz(middle_top.getX(), middle_top.getY(), middle_top.getZ() - middle_top.getZ() / 2); Zone zl(bottom, vz, -1); TreeZone *l = new TreeZone(zl); tz.addLeftChild(l); //top.setZ(vz.getZ()); middle_top = vz; } } else { if (flag2 % 3 == 0) // we cut along the x axis { Vertex vx(middle_bottom.getX() + (middle_bottom.getX() / 2), middle_bottom.getY(), middle_bottom.getZ()); Zone zr(vx, top, -1); TreeZone *r = new TreeZone(zr); tz.addRightChild(r); middle_bottom = vx; } if (flag2 % 3 == 1) // we cut along the y axis { Vertex vy(middle_bottom.getX(), middle_bottom.getY() + (middle_bottom.getY() / 2), middle_bottom.getZ()); Zone zr(vy, top, -1); TreeZone *r = new TreeZone(zr); tz.addRightChild(r); middle_bottom = vy; } if (flag2 % 3 == 2) // we cut along the z axis { Vertex vz(middle_bottom.getX(), middle_bottom.getY(), middle_bottom.getZ() + (middle_bottom.getZ() / 2)); Zone zr(vz, top, -1); TreeZone *r = new TreeZone(zr); tz.addRightChild(r); } if (depth){ if (!(*(father->getRightChild()) == tz)) { if (father->getRightChild()->getLeftChild() == NULL) { // the brother of t doesn't exist yet tz = *(father->getRightChild()); father = &(parents.back()); parents.pop_back(); } } } parents.push_back(*father); father = &tz; tz = *(tz.getLeftChild()); depth++; } } // depth-first search to add the zones we created (the leaves) into the zone vector while (tz.hasLeftChild()){ father = &tz; tz = *(tz.getLeftChild()); } tz.getRoot().setZoneId(id); m_zones.push_back(tz.getRoot()); id++; // we stop when we reach the root for the second time, i.e, when all the leaves have been found /*while(rootFlag != 1){ if (father->hasRightChild()){ father->getRightChild()->getRoot().setZoneId(id); m_zones.push_back(father->getRightChild()->getRoot()); } tz = father; if (depth){ father = parents.back(); parents.pop_back(); } depth--; }*/ return 0; }
//BUGGY, DOESN'T WORK YET void RNN::TrainWithBackPropagation(std::vector<Matrix> sequence, double learning_rate) { //do a feed forward pass, with the sequence as the input std::vector<std::vector<Matrix> > networkdata; for (int i = 0; i < sequence.size() - 2; i++) { //the first feedforward has no recurrence if (i == 0) { std::vector<Matrix> zerorecurrence; for (int j = 0; j < Num_Layers; j++) { Matrix zr(InputVectorSize, 1); zerorecurrence.push_back(zr); } networkdata.push_back(PartialFeedFoward(sequence[0], zerorecurrence)); } else { //I'm not sure which one of these is mathematically correct networkdata.push_back(PartialFeedFoward(sequence[i], networkdata[networkdata.size() - 1])); //networkdata.push_back(PartialFeedFoward(networkdata[networkdata.size() - 1][networkdata[networkdata.size() - 1].size() - 1], networkdata[networkdata.size() - 1])); } } //calculate the deltas for the network std::vector<std::vector<Matrix> > networkdeltas; //last network deltas are handled slightly differently networkdeltas.push_back(CalculateInitialDeltas(sequence[sequence.size() - 1], networkdata[networkdata.size() - 1])); //calculate the rest of the deltas for (int i = (int)sequence.size() - 2; i > 0; i--) { networkdeltas.push_back(CalculateDeltas(sequence[i], networkdata[i - 1], networkdeltas[networkdeltas.size() - 1])); } std::vector<std::vector<Matrix> > flippednetworkdeltas; //put the deltas in the right order, just makes things easier for (int i = (int)networkdeltas.size() - 1; i >= 0; i--) { flippednetworkdeltas.push_back(networkdeltas[i]); } //update weights and biases for (int i = 0; i < flippednetworkdeltas.size() - 1; i++) { //update biases for (int j = 0; j < Biases.size(); j++) { Biases[j] = Biases[j] + flippednetworkdeltas[i][j] * (-1.0f * learning_rate); } //update weights for (int j = 1; j < Weights.size(); j++) { Weights[j] = Weights[j] + ((networkdata[i][j - 1] * networkdeltas[i][j].Transpose()) * (-1.0f * learning_rate)); } //update recurrent weights if (i != flippednetworkdeltas.size() - 2) { for (int j = 1; j < RecurrentWeights.size(); j++) { for (int k = 0; k < InputVectorSize; k++) { RecurrentWeights[j].Elements[k] += networkdata[i][j].Elements[k] * networkdeltas[i + 1][j].Elements[k] * -1.0f * learning_rate; } } } } }
I rk(I f,A r,A a,A w) { A z=0,*p=0; if(w)ND2 else ND1; { XA; C *pp=0,*ap,*wp; I wt=0,wr=0,wn=0,*wd=0; I n=0,t=0,i,j,k,d[9],rw,ra,ri,ir,iw=0,ia=0,ii=0, e=!w&&f==MP(9),h=QP(f)&&f!=MP(71)&&!e; Q(!QA(r),9); Q(r->t,6); Q(r->n<1||r->n>3,8); ar-=ra=raw(ar,*r->p); if(!w) mv(d,ad,ra),ir=tr(ra,ad),ad+=ra; else { wt=w->t,wr=w->r,wd=w->d; wr-=rw=raw(wr,r->p[r->n>1]),ri=r->n>2?r->p[2]:9; Q(ri<0,9); if(ri>ra)ri=ra; if(ri>rw)ri=rw; mv(d,ad,ra-=ri); ia=tr(ra,ad),mv(d+ra,wd,rw),iw=tr(rw-=ri,wd); Q(cm(ad+=ra,wd+=rw,ri),11); ii=tr(ri,ad),ra+=rw+ri,ir=ia*iw*ii,wn=tr(wr,wd+=ri),ad+=ri; if(h&&ir>iw&&(f==MP(21)||f==MP(25)||f==MP(26)||f==MP(32)||f==MP(33))) h=0; } an=tr(ar,ad); if(h) { g=0; aw_c[0]=a->c; aw_c[1]=w&&w->c; r=(A)fa(f,gC(at,ar,an,ad,a->n?a->p:0),w?gC(wt,wr,wn,wd,w->n?w->p:0):0); aw_c[0]=aw_c[1]=1; if(!r)R 0; r=un(&r); mv(d+ra,r->d,j=r->r); if((j+=ra)>MAXR)R q=13,(I)r; n=r->n;t=r->t; if(ir<2) R mv(r->d,d,r->r=j),r->n*=ir,(I)r; dc(r); if(g==(I (*)())rsh) R rsh(w?w:a,j,d); if(!g){h=0;} else { if(at=atOnExit,w) wt=wtOnExit; if(at!=a->t&&!(a=at?ep_cf(1):ci(1))) R 0; if(w&&wt!=w->t&&!(w=wt?ep_cf(2):ci(2))) R 0; OF(i,ir,n); W(ga(t,j,i,d)); pp=(C*)z->p; } } if(!h) { W(ga(Et,ra,ir,d)); *--Y=zr(z),p=(A*)z->p; } if(!w) { for(ap=(C*)a->p;ir--;ap+=Tt(at,an)) if(h) (*(I(*)(C*,C*,I))g)(pp,ap,an),pp+=Tt(t,n); else a=gc(at,ar,an,ad,(I*)ap),*p++=e?a:(A)fa(f,(I)a,0); } else { for(i=0;i<ia;++i)for(j=0;j<iw;++j) for(k=0;k<ii;++k){ ap=(C*)a->p+Tt(at,(i*ii+k)*an); wp=(C*)w->p+Tt(wt,(j*ii+k)*wn); if(h) { (*(I(*)(C*,C*,C*,I))g)(pp,ap,wp,n),pp+=Tt(t,n); if(q==1)*--Y=(I)z,aplus_err(q,(A)Y[1]),++Y; } else { *p++=(A)fa(f,(I)gc(at,ar,an,ad,(I*)ap),(I)gc(wt,wr,wn,wd,(I*)wp)); } } } if(h)R(I)z; if(!e)z=(A)dis(r=z),dc(r); R ++Y,(I)z; } }
int main(int argc, char **argv) { if (argc != 3) { fprintf(stderr, "\n" "High Quality Zen: The batch renderer for Zen photon garden\n" "\n" "usage: hqz <scene.json> <output.png>\n" " (Either may be \"-\" for stdin/stdout)\n" "\n" "Copyright (c) 2013 Micah Elizabeth Scott <*****@*****.**>\n" "https://github.com/scanlime/zenphoton\n" "\n"); return 1; } FILE *sceneF = argv[1][0] == '-' ? stdin : fopen(argv[1], "r"); if (!sceneF) { perror("Error opening scene file"); return 2; } FILE *outputF = argv[2][0] == '-' ? stdout : fopen(argv[2], "wb"); if (!outputF) { perror("Error opening output file"); return 3; } rapidjson::FileStream istr(sceneF); rapidjson::Document scene; scene.ParseStream<0>(istr); if (scene.HasParseError()) { fprintf(stderr, "Parse error at character %ld: %s\n", scene.GetErrorOffset(), scene.GetParseError()); return 4; } ZRender zr(scene); std::vector<unsigned char> pixels; if (zr.hasError()) { fprintf(stderr, "Scene errors:\n%s", zr.errorText()); return 5; } // Render, and allow Ctrl-C to interrupt at any time. interruptibleRenderer = &zr; signal(SIGINT, handleSigint); zr.render(pixels); interruptibleRenderer = 0; if (zr.hasError()) { fprintf(stderr, "Renderer errors:\n%s", zr.errorText()); return 7; } std::vector<unsigned char> png; lodepng::encode(png, pixels, zr.width(), zr.height(), LCT_RGB); if (1 != fwrite(&png[0], png.size(), 1, outputF)) { perror("Error writing output file"); return 6; } return 0; }
Transformation Boonas:: parseParams(int start, int argc, char** argv, Transformation matrix) { QString currIn; for(int i = start; i < (argc - 1); i += 2) // iterate through parameters skiping every other { if(strcmp(argv[i], "XT") == 0) { currIn = argv[i + 1]; matrix = xt(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "YT") == 0) { currIn = argv[i + 1]; matrix = yt(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "ZT") == 0) { currIn = argv[i + 1]; matrix = zt(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "XS") == 0) { currIn = argv[i + 1]; matrix = xs(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "YS") == 0) { currIn = argv[i + 1]; matrix = ys(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "ZS") == 0) { currIn = argv[i + 1]; matrix = zs(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "US") == 0) { currIn = argv[i + 1]; matrix = us(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "XD") == 0) { currIn = argv[i + 1]; matrix = xd(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "YD") == 0) { currIn = argv[i + 1]; matrix = yd(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "ZD") == 0) { currIn = argv[i + 1]; matrix = zd(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "XR") == 0) { currIn = argv[i + 1]; matrix = xr(currIn.toFloat(), matrix); } else if(strcmp(argv[i], "YR") == 0) { currIn = argv[i + 1]; matrix = yr(currIn.toFloat(), matrix); } else // MUST BE ZR { currIn = argv[i + 1]; matrix = zr(currIn.toFloat(), matrix); } } return matrix; }