void CloudsVisualSystemCities::guiRenderEvent(ofxUIEventArgs &e)
{
    string name = e.widget->getName();
    if (name == "Size" || name == "Resolution"){
        makeGrid(size, resolution);
    }
}
예제 #2
0
    void setup() {
        int side = 32;
        int n = side * side;
        
        // first, generate some data on a random walk modulo one
        initial.clear();
        ofVec2f cur;
        ofSeedRandom(ofGetSystemTimeMicros());
        for(int i = 0; i < n; i++) {
            cur += ofVec2f(ofRandomf(), ofRandomf()) * .01;
            cur.x = fmodf(cur.x, 1);
            cur.y = fmodf(cur.y, 1);
            initial.push_back(cur);
        }
        
        // then build the grid
        grid = makeGrid(side, side);

        // and finally, match the grid to the data
        auto start = ofGetElapsedTimeMillis();
        grid = solver.match(initial, grid);
        auto stop = ofGetElapsedTimeMillis();
        
        // 625 points in 64ms
        // 1024 points in 211ms
        // 4096 points in 8841ms
        cout << grid.size() << " points in " <<  (stop - start) << "ms" << endl;
        
        ofBackground(0);
        glPointSize(6);
    }
void CloudsVisualSystemCities::selfSetup()
{
    size = 100;
    resolution = 1;
    blockSize = 1;

    grayscottLoops = 10;
    nPingPong = 0;
    diffU=0.25;
    diffV=0.04;
    k=0.047;
    f=0.2;
    
    //  Noise
    //
    noiseShader.load("", getVisualSystemDataPath()+"shaders/noise.fs");
    
    //  GrayScott
    //
    grayscottShader.load("", getVisualSystemDataPath()+"shaders/grayscott.fs");
    
    //  Mask
    //
    maskShader.load("", getVisualSystemDataPath()+"shaders/cMask.fs");
    
    //  Points
    //
    makeGrid(100, 10);
    
    //  Post
    //
    postShader.load("",getVisualSystemDataPath()+"shaders/postprocess.fs");
    ofLoadImage(postTexture, getVisualSystemDataPath()+"images/6.jpg");
}
예제 #4
0
int command_maskContent( int argc, char ** argv )
{
	if (argc < 1) ELISE_ERROR_EXIT("a *_polyg3d.ply file is needed");

	const string maskFilename = argv[1];
	cMasqBin3D *masqBin3D = cMasqBin3D::FromSaisieMasq3d(maskFilename);

	if (masqBin3D == NULL) ELISE_ERROR_EXIT("cannot load mask 3d file [" << maskFilename << "]");

	Pt3dr bbP0, bbP1;
	if (argc >= 2)
	{
		const string plyFilename = argv[1];
		getPlyBoundingBox(plyFilename, bbP0, bbP1);
		cout << "--- bounding box [" << bbP0 << ", " << bbP1 << ']' << endl;

		list<Pt3dr> inMaskPoints;
		makeGrid(bbP0, bbP1 - bbP0, 1000, *masqBin3D, inMaskPoints);
		cout << "--- " << inMaskPoints.size() << " points in mask" << endl;

		const string outputFilename = "maskContent.ply";
		if ( !writePly(inMaskPoints, outputFilename)) ELISE_ERROR_EXIT("failed to write point cloud in [" << outputFilename << ']');
	}

	delete masqBin3D;

	return EXIT_SUCCESS;
}
예제 #5
0
void UI2DGrid::guiEvent(ofxUIEventArgs &e){

    if (gui != NULL){
        string name = e.widget->getName();

        if( name == "Cross_Color"){
            ofxUIImageSampler* sampler = (ofxUIImageSampler *) e.widget;
            float alpha = cross.color.a;
            cross.color = sampler->getColor();
            cross.color.a = alpha;
        } else if( name == "Lines_Color"){
            ofxUIImageSampler* sampler = (ofxUIImageSampler *) e.widget;
            float alpha = color.a;
            color = sampler->getColor();
            color.a = alpha;
            subLines.color = color;
            subLines.color.a = color.a*subLineAlpha;
        } else if ( name == "SubLine_Alpha"){
            subLines.color.a = color.a*subLineAlpha;
        } else if( name == "Reference_Color"){
            ofxUIImageSampler* sampler = (ofxUIImageSampler *) e.widget;
            float alpha = fontColor.a;
            fontColor = sampler->getColor();
            fontColor.a = alpha;
        } else if (name == "ENABLE"){
            ofxUIToggle *t = (ofxUIToggle *) e.widget;
            bEnable = t->getValue();
        }

        makeGrid();
    }
}
예제 #6
0
파일: Polygon.cpp 프로젝트: onlyuser/Legacy
void Polygon::makeCapsule(
	IMesh *mesh, float radius, float height, int stepLng, int stepLat
	)
{
	makeGrid(mesh, stepLng + 1, stepLat * 0.5f + 2);
	float unitLng = toRad(360) / stepLng;
	float unitLat = toRad(180) / (stepLat * 0.5f);
	Vector offset = Vector(0, height, 0);
	int vertCnt = 0;
	for (int i = 0; i < stepLng + 1; i++)
	{
		for (int j = 0; j < stepLat * 0.25f + 1; j++)
		{
			Vector v =
				Vector(0, radius, 0) *
				RotateTrans(AXIS::X, j * unitLat) *
				RotateTrans(AXIS::Y, i * unitLng) *
				TranslateTrans(offset);
			mesh->setVertex(vertCnt++, v.x, v.y, v.z);
		}
		for (int k = stepLat * 0.25f; k < stepLat * 0.5f + 1; k++)
		{
			Vector v =
				Vector(0, radius, 0) *
				RotateTrans(AXIS::X, k * unitLat) *
				RotateTrans(AXIS::Y, i * unitLng);
			mesh->setVertex(vertCnt++, v.x, v.y, v.z);
		}
	}
}
예제 #7
0
void TriangleFBNELayer::
discretize(NodeMap& fixedNodes, NodeMap& allNodes, std::list< Element* >& allElements)
{
	int i, j;
	
	int m = edges[1]->size();
	int n = edges[0]->size();
	
	makeGrid( allNodes, m, n ); 
	
	std::vector<BoundaryElement*> bels[4];
	for (i = 0; i < 4; i++)
		edges[i]->elements(bels[i], directions[i]);
	
	for( j = 0; j < (n - 1); j += 2 )
		for( i = m-2; i >= 0; --i )
		{
			TriangleElement *t;
			
			t = new TriangleElement( LL, LR, UR );
			allElements.push_back( t );
			
			if (i == m - 2)
				bels[0][j]->setLeft(t->elementId());
			if (j == n - 2)
				bels[1][m - 2 - i]->setLeft(t->elementId());
			
			t = new TriangleElement( LL, UR, UL );
			allElements.push_back( t );
			
			if (i == 0)
				bels[2][n - 2 - j]->setLeft(t->elementId());
			if (j == 0)
				bels[3][i]->setLeft(t->elementId());
		}

	for( j = 1; j < (n - 1); j += 2 )
		for( i = m-2; i >= 0; --i )
		{
			TriangleElement *t;
			
			t = new TriangleElement( LL, LR, UL);
			allElements.push_back( t );
			
			if (i == m - 2)
				bels[0][j]->setLeft(t->elementId());
			
			t = new TriangleElement( LR, UR, UL);
			allElements.push_back( t );
			
			if (i == 0)
				bels[2][n - 2 - j]->setLeft(t->elementId());
			if (j == n - 2)
				bels[1][m - 2 - i]->setLeft(t->elementId());
		}

	delete [] grid;
}
예제 #8
0
파일: grid.cpp 프로젝트: byhj/Qt-OpenGL
void Grid::initBuffer()
{
    makeGrid(10, 1);
	vbo = QOpenGLBuffer(QOpenGLBuffer::VertexBuffer);
	vbo.create();
	vbo.bind();
	vbo.allocate(&VertexData[0], 84 * sizeof(QVector3D));
    vbo.release();
}
예제 #9
0
void Level::showGrid(bool show) {
    if(gridWidth != width() && gridHeight != height()) {
        gridWidth = width();
        gridHeight = height();
        makeGrid(gridSpacing);
    }

    // Draw Grid
    drawGrid = show;

    // TODO -- actually draw teh gridz
}
예제 #10
0
파일: Polygon.cpp 프로젝트: onlyuser/Legacy
void Polygon::makeCone(IMesh *mesh, int step)
{
	makeGrid(mesh, step + 1, 3);
	float unit = toRad(360) / step;
	int vertCnt = 0;
	for (int i = 0; i < step + 1; i++)
	{
		mesh->setVertex(vertCnt++, 0, 1, 0);
		Vector v =
			Vector(0, 0, 1) *
			RotateTrans(AXIS::Y, i * unit);
		mesh->setVertex(vertCnt++, v.x, v.y, v.z);
		mesh->setVertex(vertCnt++, 0, 0, 0);
	}
}
예제 #11
0
파일: Polygon.cpp 프로젝트: onlyuser/Legacy
void Polygon::makeSphere(IMesh *mesh, int stepLng, int stepLat)
{
	makeGrid(mesh, stepLng + 1, stepLat * 0.5f + 1);
	float unitLng = toRad(360) / stepLng;
	float unitLat = toRad(180) / (stepLat * 0.5f);
	int vertCnt = 0;
	for (int i = 0; i < stepLng + 1; i++)
		for (int j = 0; j < stepLat * 0.5f + 1; j++)
		{
			Vector v =
				Vector(0, 1, 0) *
				RotateTrans(AXIS::X, j * unitLat) *
				RotateTrans(AXIS::Y, i * unitLng);
			mesh->setVertex(vertCnt++, v.x, v.y, v.z);
		}
}
예제 #12
0
void MyScene::clearlyNewScene(int sceneWidth, QString mapName, QString info){
    m_mapName = mapName;
    m_info = info;
    m_sceneWidth = sceneWidth;
    //remove all images from scene and list of images
    for(int i = 0; i<m_images.length();i++)
       this->removeItem(m_images[i]);
    m_images.clear();
    //reset grid
    for(int i = 0; i<m_grid.length();i++)
       this->removeItem(m_grid[i]);
    m_grid.clear();
    makeGrid();
    m_saved = false;

}
예제 #13
0
GLWidget::GLWidget(QWidget * parent)
	: QGLWidget(parent)
{
	mouseGrabbed= false;
	movedWhileGrabbed= false;

	// movingTo initialization
	stopMoving();

	// sceneTimer is connected to sceneTimerEvent (private slot)
	sceneTimer= new QTimer(this);
	connect(sceneTimer, SIGNAL(timeout()), this, SLOT(sceneTimerEvent()));

	makeGrid(0.0,0.1,2.0);

	fileRender= false;
}
예제 #14
0
파일: Polygon.cpp 프로젝트: onlyuser/Legacy
void Polygon::makeTorus(
	IMesh *mesh, float radMajor, float radMinor, int stepMajor, int stepMinor
	)
{
	makeGrid(mesh, stepMajor + 1, stepMinor + 1);
	float unitMajor = toRad(360) / stepMajor;
	float unitMinor = toRad(360) / stepMinor;
	int vertCnt = 0;
	for (int i = 0; i < stepMajor + 1; i++)
		for (int j = 0; j < stepMinor + 1; j++)
		{
			Vector v =
				Vector(0, radMinor, 0) *
				RotateTrans(AXIS::X, j * unitMinor) *
				TranslateTrans(Vector(0, 0, radMajor)) *
				RotateTrans(AXIS::Y, i * unitMajor);
			mesh->setVertex(vertCnt++, v.x, v.y, v.z);
		}
}
예제 #15
0
//change the grid size to that spefied by ypanel and xpanel.
void Window::gridChange()
{
    int x = xpanel->text().toInt();
    int y = ypanel->text().toInt();
    if (x < 1)
        x = 1;
    else if (x > 20) {
        x = 20;
        xpanel->setText(QString::number(x));
    }
    if (y < 1)
        y = 1;
    else if (y > 20){
        y = 20;
        ypanel->setText(QString::number(y));
    }
    qDeleteAll(tiles);
    tiles.clear();
    makeGrid(x,y);
}
예제 #16
0
int main()
{
    sfwl::initContext();
    Graph<Vector2> *pGraph = makeGrid({ 80,60 }, { 720,540 }, 16, 16);

    std::vector<Vector2> dat = pGraph->getData();
    std::vector<float> mat = pGraph->getMatrix();

    Solver<Vector2> st(dat.size(), dat, mat, Comparison1, Heuristic);

    Agent sally, bob, molly;

    sally.seek.graph  = pGraph;
    sally.seek.solver = &st;

    bob.seek.graph = pGraph;
    bob.seek.solver = &st;

    molly.seek.graph = pGraph;
    molly.seek.solver = &st;

    sally.position = { 400, 300 };
    bob.position   = { 400, 300 };
    molly.position = { 400, 300 };
    while (sfwl::stepContext())
    {
        sally.update(sfwl::getDeltaTime());
        bob.update(sfwl::getDeltaTime());
        molly.update(sfwl::getDeltaTime());

        molly.draw();
        sally.draw();
        bob.draw();
    }

    sfwl::termContext();
}
예제 #17
0
MyScene::MyScene(int newPixle, QString nonePath, int sceneWidth)
{
    //set values
    ZValueCursorImage = 11;
    m_pixle = newPixle;
    m_none = nonePath;
    m_sceneWidth = sceneWidth;
    m_shift = false;
    m_shiftLeftCorner = QPointF(-1,-1);
    m_background.append(this->addPixmap(NULL));
    m_cursorImage = this->addRect(0,0,0,0);
    // set shift rectangle
    QPen *myPen = new QPen();
    myPen->setColor(Qt::green);
    myPen->setWidth(2);
    m_shiftRect = this->addRect(0,0,1,1,*myPen,Qt::lightGray);
    m_shiftRect->setZValue(ZValueCursorImage);
    m_shiftRect->setOpacity(0.4f);
    m_shiftRect->setVisible(false);
    //paint grid into scene
    makeGrid();


}
예제 #18
0
파일: ofApp.cpp 프로젝트: decebel/ofxTSNE
//--------------------------------------------------------------
void ofApp::setup(){
    
    // SETUP
    // imageDir, imageSavePath = location of images, path to save the final grid image
    // nx, ny = size of the grid (make sure there are at least nx*ny images in imageDir!)
    // w, h = downsample (or scale up) for source images prior to encoding!
    // displayW, displayH = resolution of the individual thumbnails for your output image - be careful about going over your maximum texture size on graphics card - 5000x5000 may work, but 10000x10000 may not
    // perplexity, theta (for t-SNE, see 'example' for explanation of these)
    string imageDir = "/Users/gene/Media/ImageSets/animals";
    string imageSavePath = "tsne_grid_animals.png";
    nx = 48;
    ny = 36;
    w = 256; //do not go lower than 256 - it will work, but results won't be as good
    h = 256;
    displayW = 100;
    displayH = 100;
    perplexity = 50; // corresponds to "number of neighbors", somewhere in the range 10-100 is good
    theta = 0.5; // lower is more "accurate" but takes longer, don't need to change this

    
    /////////////////////////////////////////////////////////////////////
    // CCV activations -> t-SNE embedding -> grid assignments
    
    // get images recursively from directory
    ofLog() << "Gathering images...";
    ofDirectory dir = ofDirectory(imageDir);
    scan_dir_imgs(dir);
    if (imageFiles.size() < nx * ny) {
        ofLog(OF_LOG_ERROR, "There are less images in the directory than the grid size requested (nx*ny="+ofToString((nx*ny))+"). Exiting to save you trouble...");
        ofExit(); // not enough images to fill the grid, so quitting
    }
    
    // load all the images
    for(int i=0; i<nx*ny; i++) {
        if (i % 20 == 0)    ofLog() << " - loading image "<<i<<" / "<<nx*ny<<" ("<<dir.size()<<" in dir)";
        images.push_back(ofImage());
        images.back().load(imageFiles[i]);
    }

    // resize images to w x h
    for (int i=0; i<images.size(); i++) {
        if (images[i].getWidth() > images[i].getHeight()) {
            images[i].crop((images[i].getWidth()-images[i].getHeight()) * 0.5, 0, images[i].getHeight(), images[i].getHeight());
        }
        else if (images[i].getHeight() > images[i].getWidth()) {
            images[i].crop(0, (images[i].getHeight()-images[i].getWidth()) * 0.5, images[i].getWidth(), images[i].getWidth());
        }
        images[i].resize(w, h);
    }
    
    // setup ofxCcv
    ccv.setup("image-net-2012.sqlite3");
    
    // encode all of the images with ofxCcv
    ofLog() << "Encoding images...";
    for (int i=0; i<images.size(); i++) {
        if (i % 20 == 0) ofLog() << " - encoding image "<<i<<" / "<<images.size();
        vector<float> encoding = ccv.encode(images[i], ccv.numLayers()-1);
        encodings.push_back(encoding);
    }
    
    // run t-SNE and load image points to imagePoints
    ofLog() << "Run t-SNE on images";
    tsneVecs = tsne.run(encodings, 2, perplexity, theta, true);
    
    // solve assignment grid
    vector<ofVec2f> tsnePoints; // convert vector<double> to ofVec2f
    for (auto t : tsneVecs) tsnePoints.push_back(ofVec2f(t[0], t[1]));
    vector<ofVec2f> gridPoints = makeGrid(nx, ny);
    solvedGrid = solver.match(tsnePoints, gridPoints, false);
    
    // save
    ofFbo fbo;
    fbo.allocate(nx * displayW, ny * displayH);
    fbo.begin();
    ofClear(0, 0);
    ofBackground(0);
    for (int i=0; i<solvedGrid.size(); i++) {
        float x = (fbo.getWidth() - displayW) * solvedGrid[i].x;
        float y = (fbo.getHeight() - displayH) * solvedGrid[i].y;
        images[i].draw(x, y, displayW, displayH);
    }
    fbo.end();
    ofImage img;
    fbo.readToPixels(img);
    img.save(imageSavePath);
    
    // setup gui
    gui.setup();
    gui.add(scale.set("scale", 1.0, 0.0, 1.0));
}
예제 #19
0
//init all the basic elements of the window.
Window::Window()
{
    this->setWindowTitle("Sanajahti");
    //init some text labels
    QLabel* label1 = new QLabel("Width:", this);
    label1->move(5, 10);

    QLabel* label2 = new QLabel("Height:", this);
    label2->move(80, 10);

    QLabel* label4 = new QLabel("Words", this);
    label4->move(3,68);

    //init textpanel for x length
    xpanel = new QLineEdit("4", this);
    xpanel->move(52, 4);
    xpanel->setFixedWidth(25);
    xpanel->setValidator(new QIntValidator(1, 99, this));
    connect(xpanel, SIGNAL(textChanged(const QString &)), this, SLOT(gridChange()));

    //init textpanel for y length
    ypanel= new QLineEdit("4", this);
    ypanel->move(132, 4);
    ypanel->setFixedWidth(25);
    ypanel->setValidator(new QIntValidator(1, 99, this));
    connect(ypanel, SIGNAL(textChanged(const QString &)), this, SLOT(gridChange()));

    //init textpanel for library path
    library_path = new QLineEdit("", this);
    library_path->move(5, 33);
    library_path->setFixedWidth(90);
    library_path->setReadOnly(true);
    library_path->setStyleSheet("background-color:lightgrey");

    //init button to select library
    browse_button = new QPushButton("Library", this);
    browse_button->move(95, 34);
    browse_button->setFixedWidth(65);
    connect(browse_button, SIGNAL(clicked()), this, SLOT(browse()));

    //init startbutton
    start_button = new QPushButton("Start", this);
    start_button->move(3, 91);
    start_button->setFixedWidth(58);
    connect(start_button,SIGNAL(clicked()), this, SLOT(manual_start()));

    restart_button = new QPushButton("Restart", this);
    restart_button->move(3, 91);
    restart_button->setFixedWidth(58);
    restart_button->setHidden(true);
    connect(restart_button, SIGNAL(clicked()), this, SLOT(restart()));

    //init button for adb controlling
    adb_button = new QPushButton("Auto Solve", this);
    adb_button->move(62, 91);
    connect(adb_button, SIGNAL(clicked()), this, SLOT(adb_start()));

    //init combobox for wordlist
    list = new QComboBox(this);
    list->move(52,62);
    list->setFixedWidth(105);
    list->setDisabled(true);
    connect(list, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(drawWord(const QString &)));

    //init mapper for pairing tile textChanged() signals to widget calling it
    mapper = new QSignalMapper(this);
    connect(mapper, SIGNAL(mapped(int)), this, SLOT(valueChanged(int)));

    path=QDir::currentPath();

    //call function to create 4x4 grid
    makeGrid(4,4);
}
예제 #20
0
파일: main.c 프로젝트: jpdoyle/GRender
int main(void) {
    unsigned ticksPerFrame = 1000/FRAMES_PER_SECOND;
    SDL_Surface* screen;
    Context* ct;

    if(SDL_Init(SDL_INIT_EVERYTHING) != 0) {
        fprintf(stderr,"SDL init failed");
        return -1;
    }
    if(!(screen = SDL_SetVideoMode(SCREEN_WIDTH,SCREEN_HEIGHT,
                                   SCREEN_BPP,SDL_SWSURFACE))) {
        fprintf(stderr,"SDL video init failed");
        return -1;
    }
    if(!(ct = createContext(SCREEN_WIDTH,SCREEN_HEIGHT))) {
        fprintf(stderr,"Context init failed");
        return -1;
    }

    ct->depthEnabled = 1;
    ct->cullBackFace = 1;
    ct->frontFace    = WINDING_CCW;

    ct->vertShader = &shadeVertex;
    ct->fragShader = &shadeFragment;

    mat44Perspective(matStackTop(ct->matrices[MATRIX_PROJECTION]),
                     FOVY,SCREEN_WIDTH/(float)SCREEN_HEIGHT,1,30);

    printf("Projection:\n");
    mat44Print(stdout,matStackTop(ct->matrices[MATRIX_PROJECTION]));

    mat44Ident(matStackTop(ct->matrices[MATRIX_MODELVIEW]));

    Mat44 translate;
    mat44Translate(translate,0,0,-4);

    Mat44 rotateVert;
    mat44Ident(rotateVert);

    Mat44 tetraTransform;
    mat44Ident(tetraTransform);

    float tetraHorizRot = 0,
          tetraVertRot  = 0;

    VertexArray* varr = createVertArray(0,NULL);
    varr->locs      = &verts[0].loc;
    varr->locStep   = sizeof(CustomVert);
    varr->colors    = &verts[0].color;
    varr->colorStep = sizeof(CustomVert);

    Color4 black = { 0,0,0,0 };

    CustomVert* gridVerts;
    unsigned*   gridIndices;
    unsigned    gridNumEdges;
    makeGrid(&gridVerts,&gridIndices,&gridNumEdges,
             -6,-6,6,6,12,12);

    VertexArray* gridArr = createVertArray(0,NULL);

    gridArr->locs      = &gridVerts[0].loc;
    gridArr->locStep   = sizeof(CustomVert);
    gridArr->colors    = &gridVerts[0].color;
    gridArr->colorStep = sizeof(CustomVert);

    Mat44 gridTransform;
    mat44Translate(gridTransform,0,-5,0);

    SDL_WM_SetCaption(TITLE,NULL);

    char title[256];
    float fps = 0;
    float fpsLerp = 0.2;

    int numViewports = 1;

    int mouseCaptured = 0;
    int running = 1;
    int debugged = 0;
    while(running) {
        Uint32 startTicks = SDL_GetTicks();

        int vertRot  = 0,
            horizRot = 0;

        SDL_Event event;
        while(SDL_PollEvent(&event)) {
            switch(event.type) {
                case SDL_QUIT:
                    running = 0;
                    break;
                case SDL_KEYDOWN:
                    switch(event.key.keysym.sym) {
                    case SDLK_ESCAPE:
                        mouseCaptured = !mouseCaptured;
                        SDL_ShowCursor(mouseCaptured ? SDL_DISABLE :
                                                       SDL_ENABLE);
                        break;
                    case SDLK_p:
                        debugged = 0;
                        break;
                    case SDLK_BACKQUOTE:
                        if(numViewports == 1) {
                            numViewports = 2;
                        } else {
                            numViewports = 1;
                        }
                        mat44Perspective(matStackTop(ct->matrices[MATRIX_PROJECTION]),
                                         FOVY,SCREEN_WIDTH/(float)numViewports/SCREEN_HEIGHT,1,30);
                        break;
                    default:
                        break;
                    }
                    break;
                case SDL_MOUSEMOTION:
                    if(mouseCaptured) {
                        SDL_WarpMouse(SCREEN_WIDTH/2,SCREEN_HEIGHT/2);
                        horizRot = -event.motion.xrel,
                        vertRot  = event.motion.yrel;
                    }
                    break;
                default:
                    break;
            }
        }

        if(!debugged) {
            printf("\nDebugging!\n\n");
        }

        clearColorBuffer(ct);
        fillDepthBuffer(ct,1);
        /* fillBuffers(ct,black,1); */
        
        Uint8* keys = SDL_GetKeyState(NULL);

        if(!mouseCaptured) {
            vertRot = horizRot = 0;
            if(keys[SDLK_UP]) {
                vertRot += 1;
            }
            if(keys[SDLK_DOWN]) {
                vertRot -= 1;
            }

            if(keys[SDLK_RIGHT]) {
                horizRot += 1;
            }
            if(keys[SDLK_LEFT]) {
                horizRot -= 1;
            }
        }

        int xDelta = 0,
            yDelta = 0,
            zDelta = 0;
        if(keys[SDLK_w]) { 
            zDelta -= 1;
        }
        if(keys[SDLK_s]) {
            zDelta += 1;
        }
        if(keys[SDLK_a]) { 
            xDelta -= 1;
        }
        if(keys[SDLK_d]) {
            xDelta += 1;
        }
        if(keys[SDLK_RSHIFT] || keys[SDLK_LSHIFT]) {
            yDelta -= 1;
        }
        if(keys[SDLK_SPACE]) {
            yDelta += 1;
        }

        Mat44 tmp;

        if(xDelta || yDelta || zDelta) {
            float xDiff = xDelta*MOVEMENT_SPEED*SECONDS_PER_FRAME,
                  yDiff = yDelta*MOVEMENT_SPEED*SECONDS_PER_FRAME,
                  zDiff = zDelta*MOVEMENT_SPEED*SECONDS_PER_FRAME;
            mat44Translate(tmp,-xDiff,-yDiff,-zDiff);
            mat44Mult(translate,tmp,translate);
        }

        if(vertRot) {
            float vertDiff = vertRot*(mouseCaptured ?
                                       DEGREES_PER_PIXEL :
                                       ROTATION_SPEED*SECONDS_PER_FRAME);
            mat44Rotate(tmp,vertDiff,-1,0,0);
            mat44Mult(rotateVert,tmp,rotateVert);
        }
        if(horizRot) {
            float horizDiff = horizRot*(mouseCaptured ?
                                       DEGREES_PER_PIXEL :
                                       ROTATION_SPEED*SECONDS_PER_FRAME);
            mat44Rotate(tmp,horizDiff,0,1,0);
            mat44Mult(translate,tmp,translate);
        }

        tetraHorizRot += TETRA_HORIZ_ROTATION_SPEED*SECONDS_PER_FRAME;
        tetraVertRot  += TETRA_VERT_ROTATION_SPEED *SECONDS_PER_FRAME;

        mat44Rotate(tetraTransform,tetraHorizRot,0,1,0);

        mat44Rotate(tmp,tetraHorizRot,0,1,0);
        Vec4 xAxis = { 1,0,0,1 };
        mat44MultVec4(xAxis,tmp,xAxis);
        mat44Rotate(tmp,tetraVertRot,xAxis[0],xAxis[1],xAxis[2]);
        mat44Mult(tetraTransform,tetraTransform,tmp);


        ct->viewport.width = ct->_width/numViewports;

        unsigned i;
        for(i=0;i<numViewports;++i) {
            ct->viewport.x = ct->_width-ct->viewport.width*(i+1);

            matStackPush(ct->matrices[MATRIX_MODELVIEW]);

                if(i == 0) {
                    matStackMult(ct->matrices[MATRIX_MODELVIEW],rotateVert);
                    matStackMult(ct->matrices[MATRIX_MODELVIEW],translate);
                } else {
                    mat44Translate(tmp,0,0,-5);
                    matStackMult(ct->matrices[MATRIX_MODELVIEW],tmp);
                }

                //drawShapeIndexed(ct,SHAPE_TRIANGLE,4,varr,indices);
                matStackPush(ct->matrices[MATRIX_MODELVIEW]);

                    matStackMult(ct->matrices[MATRIX_MODELVIEW],gridTransform);
                    
                    drawShapeIndexed(ct,SHAPE_LINE,gridNumEdges,gridArr,gridIndices);

                matStackPop(ct->matrices[MATRIX_MODELVIEW]);
    
                matStackPush(ct->matrices[MATRIX_MODELVIEW]);
    
                    matStackMult(ct->matrices[MATRIX_MODELVIEW],tetraTransform);
    
                    drawShapeIndexed(ct,SHAPE_TRIANGLE,4,varr,indices);

                matStackPop(ct->matrices[MATRIX_MODELVIEW]);
                
            matStackPop(ct->matrices[MATRIX_MODELVIEW]);
            
            debugged = 1;
        }

        SDL_BlitSurface(ct->surface,NULL,screen,NULL);
        SDL_Flip(screen);

        unsigned elapsedTime = SDL_GetTicks()-startTicks;
        /* printf("%d ms/frame\n",elapsedTime); */
        unsigned currFps = 1000/elapsedTime;
        if(currFps > FRAMES_PER_SECOND) {
            currFps = FRAMES_PER_SECOND;
        }

        fps = fpsLerp*currFps+(1-fpsLerp)*fps;
        sprintf(title,"%s %u/%u ms%s",TITLE,elapsedTime,ticksPerFrame,
                                      elapsedTime > ticksPerFrame ? "!!":"");
        SDL_WM_SetCaption(title,NULL);

        if(elapsedTime < ticksPerFrame) {
            SDL_Delay(ticksPerFrame-elapsedTime);
        }
    }

    free(gridVerts);
    free(gridIndices);

    freeVertArray(gridArr);
    freeVertArray(varr);

    freeContext(ct);
    return 0;
}
  void initEvent()
  {
    vl::Log::notify(appletInfo());

    if(!vl::Has_GL_Version_4_0)
    {
      vl::Log::error("This test requires OpenGL 4!\n");
      vl::Time::sleep(2000);
      exit(1);
    }

    const int   patch_count      = 128;
    const float world_size       = 2500.0;
    const float height_scale     = 150.0;
    const float pixel_per_edge   = 16.0f;
    const float max_tessellation = 64.0f;

    vl::ref< vl::Geometry > geom_patch = makeGrid( vl::vec3(), world_size, world_size, patch_count, patch_count, false );

    geom_patch->convertToVertexAttribs();

    // patch parameter associated to the draw call
    vl::ref<vl::PatchParameter> patch_param = new vl::PatchParameter;
    patch_param->setPatchVertices(4);
    geom_patch->drawCalls()->at(0)->setPatchParameter( patch_param.get() );
    geom_patch->drawCalls()->at(0)->setPrimitiveType(vl::PT_PATCHES);

    vl::ref<vl::Texture> hmap = new vl::Texture("/images/ps_height_4k.jpg", vl::TF_RED, false, false);
    vl::ref<vl::Texture> tmap = new vl::Texture("/images/ps_texture_4k.jpg", vl::TF_RGBA, true, false);

    hmap->getTexParameter()->setMinFilter(vl::TPF_LINEAR);
    hmap->getTexParameter()->setMagFilter(vl::TPF_LINEAR);

    // tessellated patches fx
    vl::ref<vl::Effect> fx = new vl::Effect;
    fx->shader()->enable(vl::EN_DEPTH_TEST);
    fx->shader()->gocTextureSampler(0)->setTexture( hmap.get() );
    fx->shader()->gocTextureSampler(1)->setTexture( tmap.get() );

    // bind all the necessary stages to the GLSLProgram
    mGLSL = fx->shader()->gocGLSLProgram();
    mGLSL->attachShader( new vl::GLSLVertexShader("glsl/tess_grid.vs") );
    mGLSL->attachShader( new vl::GLSLTessControlShader("glsl/tess_grid.tcs") );
    mGLSL->attachShader( new vl::GLSLTessEvaluationShader("glsl/tess_grid.tes") );
    mGLSL->attachShader( new vl::GLSLFragmentShader("glsl/tess_grid.fs") );
    mGLSL->gocUniform("pixel_per_edge")->setUniformF(pixel_per_edge);
    mGLSL->gocUniform("max_tessellation")->setUniformF(max_tessellation);
    mGLSL->gocUniform("screen_size")->setUniform(vl::fvec2(512,512));
    mGLSL->gocUniform("world_size")->setUniformF(world_size);
    mGLSL->gocUniform("height_scale")->setUniformF(height_scale);
    mGLSL->gocUniform("tex_heghtmap")->setUniformI(0);
    mGLSL->gocUniform("tex_diffuse")->setUniformI(1);

    mGLSL->addAutoAttribLocation( 0, "vl_Position" );

    // tessellated patches fx_wire
    vl::ref<vl::Effect> fx_wire = new vl::Effect;
    fx_wire->shader()->enable(vl::EN_DEPTH_TEST);
    fx_wire->shader()->gocPolygonMode()->set(vl::PM_LINE, vl::PM_LINE);
    fx_wire->shader()->gocTextureSampler(0)->setTexture( hmap.get() );
    fx_wire->shader()->gocPolygonOffset()->set(-1.0f, -1.0f);
    fx_wire->shader()->enable(vl::EN_POLYGON_OFFSET_LINE);

    // bind all the necessary stages to the GLSLProgram
    mGLSLWire = fx_wire->shader()->gocGLSLProgram();
    mGLSLWire->attachShader( new vl::GLSLVertexShader("glsl/tess_grid.vs") );
    mGLSLWire->attachShader( new vl::GLSLTessControlShader("glsl/tess_grid.tcs") );
    mGLSLWire->attachShader( new vl::GLSLTessEvaluationShader("glsl/tess_grid.tes") );
    mGLSLWire->attachShader( new vl::GLSLFragmentShader("glsl/tess_grid_wire.fs") );
    mGLSLWire->gocUniform("pixel_per_edge")->setUniformF(pixel_per_edge);
    mGLSLWire->gocUniform("max_tessellation")->setUniformF(max_tessellation);
    mGLSLWire->gocUniform("screen_size")->setUniform(vl::fvec2(512,512));
    mGLSLWire->gocUniform("world_size")->setUniformF(world_size);
    mGLSLWire->gocUniform("height_scale")->setUniformF(height_scale);
    mGLSLWire->gocUniform("tex_heghtmap")->setUniformI(0);
    mGLSLWire->gocUniform("wire_color")->setUniform(vl::lightgreen);

    mGLSLWire->addAutoAttribLocation( 0, "vl_Position" );

    sceneManager()->tree()->addActor( geom_patch.get(), fx.get(), NULL )->setRenderRank(0);
    
    mWireActor = sceneManager()->tree()->addActor( geom_patch.get(), fx_wire.get(), NULL );
    mWireActor->setRenderRank(1);

    // debugging
    #if 0
      // base patch grid
      vl::ref< vl::Geometry > geom_quads = makeGrid(vl::fvec3(), world_size,world_size, patch_count,patch_count, true);
      geom_quads->setColor(vl::red);
      // base patch grid fx
      vl::ref<vl::Effect> fx_grid = new vl::Effect;
      fx_grid->shader()->gocPolygonMode()->set(vl::PM_LINE, vl::PM_LINE);
      // add grid
      sceneManager()->tree()->addActor( geom_quads.get(), fx_grid.get(), NULL )->setRenderRank(2);
    #endif
  }
예제 #22
0
파일: ofApp.cpp 프로젝트: bensnell/torsos
//--------------------------------------------------------------
void ofApp::setup(){
    
    // SETUP
    // imageDir, imageSavePath = location of images, path to save the final grid image
    // nx, ny = size of the grid (make sure there are at least nx*ny images in imageDir!)
    // w, h = size of the image thumbnails
    // perplexity, theta (for t-SNE, see 'example' for explanation of these)
    
    // -------------- SET FILE I/O ---------------
    
    string imageDir = "../../../../../../../../../Volumes/BenSnell/torsos-7k/photos-jpg"; // source directory
    
    string folderName = "torsos_7k_all"; // destination directory

    // -------------------------------------------
    
    nx = 87;
    ny = 87;
    w = 340;
    h = 510;
    perplexity = 75;
    theta = 0.001;

    
    /////////////////////////////////////////////////////////////////////
    // CCV activations -> t-SNE embedding -> grid assignments
    
    // get images recursively from directory
    ofLog() << "Gathering images...";
    ofDirectory dir = ofDirectory(imageDir);
    scan_dir_imgs(dir);
    if (imageFiles.size() < nx * ny) {
        ofLog(OF_LOG_ERROR, "There are less images in the directory than the grid size requested (nx*ny="+ofToString((nx*ny))+"). Exiting to save you trouble...");
//        ofExit(); // not enough images to fill the grid, so quitting
    }
    
    // load all the images
//    for(int i=0; i<nx*ny; i++) {
//        if (i % 20 == 0)    ofLog() << " - loading image "<<i<<" / "<<nx*ny<<" ("<<dir.size()<<" in dir)";
//        images.push_back(ofImage());
//        images.back().load(imageFiles[i]);
////        images.back().resize(w, h); // ADDED -- DOES THIS WORK?
//    }
    for(int i=0; i<imageFiles.size(); i++) {
        if (i % 20 == 0)    ofLog() << " - loading image "<<i<<" / "<<imageFiles.size()<<" ("<<dir.size()<<" in dir)";
        images.push_back(ofImage());
        images.back().load(imageFiles[i]);
        //        images.back().resize(w, h); // ADDED -- DOES THIS WORK?
    }
    

    // resize images to w x h
    for (int i=0; i<images.size(); i++) {
        if (images[i].getWidth() > images[i].getHeight()) {
            images[i].crop((images[i].getWidth()-images[i].getHeight()) * 0.5, 0, images[i].getHeight(), images[i].getHeight());
        }
        else if (images[i].getHeight() > images[i].getWidth()) {
            images[i].crop(0, (images[i].getHeight()-images[i].getWidth()) * 0.5, images[i].getWidth(), images[i].getWidth());
        }
        images[i].resize(w, h);
    }
    
    // setup ofxCcv
    ccv.setup("image-net-2012.sqlite3");
    
    // encode all of the images with ofxCcv
    ofLog() << "Encoding images...";
    for (int i=0; i<images.size(); i++) {
        if (i % 20 == 0) ofLog() << " - encoding image "<<i<<" / "<<images.size();
        vector<float> encoding = ccv.encode(images[i], ccv.numLayers()-1);
        encodings.push_back(encoding);
    }
    
    // run t-SNE and load image points to imagePoints
    ofLog() << "Run t-SNE on images";
    tsneVecs = tsne.run(encodings, 2, perplexity, theta, true);
    // tsneVecs contains {x, y} for each image in images
    
    // save tsne
    ofFile tsneFile;
    tsneFile.open(folderName + "/" + "tsne_only_metadata.csv", ofFile::WriteOnly);
    tsneFile << "image_name,tsne_x,tsne_y";
    for (int i = 0; i < images.size(); i++) {
        tsneFile << "\n";
        tsneFile << imageFiles[i].getFileName() << ",";
        tsneFile << ofToString(tsneVecs[i][0]) << ",";
        tsneFile << ofToString(tsneVecs[i][1]);
    }
    tsneFile.close();
    
    ofExit(); // TEMP!!!
    
    // solve assignment grid
    vector<ofVec2f> tsnePoints; // convert vector<double> to ofVec2f
    for (auto t : tsneVecs) tsnePoints.push_back(ofVec2f(t[0], t[1]));
    vector<ofVec2f> gridPoints = makeGrid(nx, ny);
    solvedGrid = solver.match(tsnePoints, gridPoints, false);
    
    // export data to csv containing names and positions of images
    bool bExport = true;
    if (bExport) {
        int nImages = images.size(); //nx * ny;
        ofFile file;
        file.open(folderName + "/" + "tsne_metadata.csv", ofFile::WriteOnly);
        file << "image_name,grid_row,grid_column,grid_x_norm,grid_y_norm,tsne_x,tsne_y";
        for (int i = 0; i < nImages; i++) {
            file << "\n";
            file << imageFiles[i].getFileName() << ",";
            file << ofToString(solvedGrid[i].x * (nx-1)) << ",";
            file << ofToString(solvedGrid[i].y * (ny-1)) << ",";
            file << ofToString(solvedGrid[i].x) << ",";
            file << ofToString(solvedGrid[i].y) << ",";
            file << ofToString(tsneVecs[i][0]) << ",";
            file << ofToString(tsneVecs[i][1]);
        }
        file.close();
    }
    
    // save image grid
    bool bSaveGrid = true;
    if (bSaveGrid) {
        string imageGridName = "tsne_grid.png";
        ofFbo fbo;
        fbo.allocate(nx * w, ny * h);
        fbo.begin();
        ofClear(0, 0);
        ofBackground(0);
        for (int i=0; i<solvedGrid.size(); i++) {
            float x = (fbo.getWidth() - w) * solvedGrid[i].x;
            float y = (fbo.getHeight() - h) * solvedGrid[i].y;
            images[i].draw(x, y, w, h);
        }
        fbo.end();
        ofImage img;
        fbo.readToPixels(img);
        img.save(folderName + "/" + imageGridName);
    }
    
    // save image clusters
    bool bSaveClusters = true;
    float imgScale = 0.5;
    if (bSaveClusters) {
        string imageClustersName = "tsne_clusters.png";
        ofFbo fbo;
        fbo.allocate(nx * w, ny * h);
        fbo.begin();
        ofClear(0, 0);
        ofBackground(255);
        for (int i=0; i<tsneVecs.size(); i++) {
            float x = (fbo.getWidth() - w) * tsneVecs[i][0];
            float y = (fbo.getHeight() - h) * tsneVecs[i][1];
            ofSetColor(255, 180);
            images[i].draw(x, y, w * imgScale, h * imgScale);
            ofSetColor(0);
            ofDrawBitmapString(imageFiles[i].getFileName(), x, y + h * imgScale);
        }
        fbo.end();
        ofImage img;
        fbo.readToPixels(img);
        img.save(folderName + "/" + imageClustersName);
    }
    
    // setup gui
    gui.setup();
    gui.add(scale.set("scale", 1.0, 0.0, 1.0));
}
예제 #23
0
static double aRate(double X, int everage,int Fast, float ** wPrc)
{
  double Sum=0.;
  int i,l1,l2;
  int nPrc=0;
  char* pname[5];
  gridStr grid,grid1;
  double MassCutOut=MassCut+M*log(100.)/X;
  double Msmall,Mlarge;

  int nPrcTot=0;

  if(MassCutOut<M*(2+10/X)) MassCutOut=M*(2+10/X); 

  xf_=X;
  exi=everage;

  if(wPrc) *wPrc=NULL;

  for(l1=0;l1<NC;l1++)
  { int k1=sort[l1]; if(M+inMass[k1]>MassCut) break;
  for(l2=0;l2<NC;l2++)
  {
    double Sumkk=0.;
    double x[2],f[2];
    double factor;
    int k2=sort[l2];
    CalcHEP_interface * CI;

    if(inMass[k1]+inMass[k2] > MassCut) break;

    if(inC[k1*NC+k2]<=0) continue;
    if(code22[k1*NC+k2]==NULL) new_code(k1,k2);
    if(inC[k1*NC+k2]<=0) continue;


    if(!code22[k1*NC+k2]->init)
    { numout * cd=code22[k1*NC+k2];
      CalcHEP_interface *cdi=cd->interface;
      for(i=1;i<=cdi->nvar;i++) if(cd->link[i]) cdi->va[i]=*(cd->link[i]);
      
      if( cdi->calcFunc()>0 ) {FError=1; return -1;}
      cd->init=1;
    }

    if(wPrc)
    {  nPrcTot+=code22[k1*NC+k2]->interface->nprc;
       *wPrc=(float*)realloc(*wPrc,sizeof(float)*(nPrcTot));
    }

    sqme=code22[k1*NC+k2]->interface->sqme;
    DeltaXf=(inDelta[k1]+inDelta[k2])*X;
    inBuff=0;

    M1=inMass[k1];
    M2=inMass[k2];

    Msmall=M1>M2? M1-M*(1-sWidth): M2-M*(1-sWidth);
    Mlarge=M1>M2? M2+M*(1-sWidth): M1+M*(1-sWidth);

    u_max=m2u(MassCutOut);
    if(Fast)
    { 
      if(Fast==1)
      {  double c[4];

         for(Npow=0;Npow<4;Npow++) c[Npow]=simpson(s_pow_integrand, 0. ,1. ,1.E-4);
         gaussC2(c,x,f);
         for(i=0;i<2;i++){ x[i]=sqrt(x[i]); f[i]*=2*x[i]/M;}
      }else 
      {
         double c[2];
         for(Npow=0;Npow<2;Npow++) c[Npow]=simpson(s_pow_integrand, 0. ,1. ,1.E-4);
         x[0]= sqrt(c[1]/c[0]);
         f[0]= c[0]*2*x[0]/M;
      }
    }
    factor=inC[k1*NC+k2]*inG[k1]*inG[k2]*exp(-DeltaXf);
    CI=code22[k1*NC+k2]->interface;
    for(nsub=1; nsub<= CI->nprc;nsub++,nPrc++)
    { double u_min=0.;
      double a=0;

      if(wPrc) (*wPrc)[nPrc]=0;

      for(i=0;i<4;i++)  pname[i]=CI->pinf(nsub,i+1,pmass+i,NULL);
      if(pmass[2]+pmass[3]>MassCutOut) continue;

      if( (pmass[2]>Mlarge && pmass[3]<Msmall)
        ||(pmass[3]>Mlarge && pmass[2]<Msmall))
           { *(CI->twidth)=1; *(CI->gtwidth)=1;}
      else { *(CI->twidth)=0; *(CI->gtwidth)=0;}
      *(CI->gswidth)=0;
                             
      if(pmass[2]+pmass[3] > pmass[0]+pmass[1])
      { double smin=pmass[2]+pmass[3];
        if((pmass[0]!=M1 || pmass[1]!=M2)&&(pmass[0]!=M2 || pmass[1]!=M1))
        { double ms=pmass[0]+pmass[1];
          double md=pmass[0]-pmass[1];
          double Pcm=sqrt((smin-ms)*(smin+ms)*(smin-md)*(smin+md))/(2*smin);
          smin=sqrt(M1*M1+Pcm*Pcm)+sqrt(M2*M2+Pcm*Pcm);
        }
        u_min=m2u(smin); 
      }else  u_min=0;
      
repeat:
      neg_cs_flag=0;
      if(!Fast) a=simpson(s_integrand,u_min,1.,eps); 
      else if(Fast!=1) a=f[0]*sigma(x[0]); else
      {
          int isPole=0;
          char * s;
          int m,w,n;
          double mass,width;

          for(n=1;(s=code22[k1*NC+k2]->interface->den_info(nsub,n,&m,&w));n++)
          if(m && w && strcmp(s,"\1\2")==0 )
          { mass=code22[k1*NC+k2]->interface->va[m];
            width=code22[k1*NC+k2]->interface->va[w];
            if(mass<MassCutOut && mass+8*width > pmass[0]+pmass[1]
                            && mass+8*width > pmass[2]+pmass[3])
            { if((pmass[0]!=M1 || pmass[1]!=M2)&&(pmass[0]!=M2 || pmass[1]!=M1))
              { double ms=pmass[0]+pmass[1];
                double md=pmass[0]-pmass[1];
                double Pcm=sqrt((mass-ms)*(mass+ms)*(mass-md)*(mass+md))/(2*mass);
                mass=sqrt(M1*M1+Pcm*Pcm)+sqrt(M2*M2+Pcm*Pcm);
              }
              grid1=makeGrid(mass,width);
              if(isPole) grid=crossGrids(&grid,&grid1); else grid=grid1;
              isPole++;
            }
          }
          if(isPole==0)
          {  grid.n=1;
             grid.ul[0]=u_min;
             grid.ur[0]=u_max;
             grid.pow[0]=3;
          }

          if(grid.n==1 && pmass[0]+pmass[1]> 1.1*(pmass[2]+pmass[3]))
                a=f[0]*sigma(x[0])+f[1]*sigma(x[1]);
          else for(i=0;i<grid.n;i++)if(u_min<=grid.ur[i])
          {  
             double ul= u_min<grid.ul[i]? grid.ul[i]:u_min;
             double da=gauss(s_integrand,ul,grid.ur[i],grid.pow[i]);
             a+=da;             
          }
      }
      if(neg_cs_flag && *(CI->gswidth)==0)
      { *(CI->gswidth)=1;
         goto  repeat;
      }   
/* 
printf("X=%.2E (%d) %.3E %s %s %s %s\n",X,everage, a, pname[0],pname[1],pname[2],pname[3]);
*/
      Sumkk+=a;
      if(wPrc) (*wPrc)[nPrc] = a*factor;
    }
    Sum+=factor*Sumkk;
/*
printf("Sum=%E\n",Sum);
*/
  }
  }
  if(wPrc) for(i=0; i<nPrc;i++)  (*wPrc)[i]/=Sum;
  if(!everage) { double gf=geff(X);  Sum/=gf*gf;}
/*
exit(1);
*/
  return Sum;
}
예제 #24
0
파일: game.c 프로젝트: dibas/portalDS
void initGame(void)
{
	lcdMainOnTop();
	int oldv=getMemFree();
	NOGBA("mem free : %dko (%do)",getMemFree()/1024,getMemFree());
	NOGBA("initializing...");
	videoSetMode(MODE_5_3D | DISPLAY_BG3_ACTIVE);
	videoSetModeSub(MODE_5_2D | DISPLAY_BG3_ACTIVE);
	
	glInit();
	
	vramSetPrimaryBanks(VRAM_A_TEXTURE,VRAM_B_TEXTURE,VRAM_C_LCD,VRAM_D_MAIN_BG_0x06000000);
	vramSetBankH(VRAM_H_SUB_BG);
	vramSetBankI(VRAM_I_SUB_BG_0x06208000);
	
	glEnable(GL_TEXTURE_2D);
	// glEnable(GL_ANTIALIAS);
	glDisable(GL_ANTIALIAS);
	glEnable(GL_BLEND);
	glEnable(GL_OUTLINE);
	
	glSetOutlineColor(0,RGB15(0,0,0)); //TEMP?
	glSetOutlineColor(1,RGB15(0,0,0)); //TEMP?
	glSetOutlineColor(7,RGB15(31,0,0)); //TEMP?
	glSetToonTableRange(0, 15, RGB15(8,8,8)); //TEMP?
	glSetToonTableRange(16, 31, RGB15(24,24,24)); //TEMP?
	
	glClearColor(31,31,0,31);
	glClearPolyID(63);
	glClearDepth(0x7FFF);

	glViewport(0,0,255,191);
	
	// initVramBanks(1);
	initVramBanks(2);
	initTextures();
	initSound();
	
	initCamera(NULL);
	
	initPlayer(NULL);
	
	initLights();
	initParticles();
	
	initMaterials();
	
	loadMaterialSlices("slices.ini");
	loadMaterials("materials.ini");
	loadControlConfiguration("config.ini");
	
	initElevators();
	initWallDoors();
	initTurrets();
	initBigButtons();
	initTimedButtons();
	initEnergyBalls();
	initPlatforms();
	initCubes();
	initEmancipation();
	initDoors();
	initSludge();
	initPause();

	initText();

	NOGBA("lalala");

	getPlayer()->currentRoom=&gameRoom;
	
	currentBuffer=false;
	
	getVramStatus();
	fadeIn();
	
	mainBG=bgInit(3, BgType_Bmp16, BgSize_B16_256x256, 0, 0);
	bgSetPriority(mainBG, 0);
	REG_BG0CNT=BG_PRIORITY(3);
	
	#ifdef DEBUG_GAME
		consoleInit(&bottomScreen, 3, BgType_Text4bpp, BgSize_T_256x256, 16, 0, false, true);
		consoleSelect(&bottomScreen);
	#endif
	
	// glSetToonTableRange(0, 14, RGB15(16,16,16));
	// glSetToonTableRange(15, 31, RGB15(26,26,26));
	
	initPortals();
	
	//PHYSICS
	initPI9();

	strcpy(&mapFilePath[strlen(mapFilePath)-3], "map");
	newReadMap(mapFilePath, NULL, 255);
	
	transferRectangles(&gameRoom);
	makeGrid();
	generateRoomGrid(&gameRoom);
	gameRoom.displayList=generateRoomDisplayList(&gameRoom, vect(0,0,0), vect(0,0,0), false);
	
	getVramStatus();
	
	startPI();

	NOGBA("START mem free : %dko (%do)",getMemFree()/1024,getMemFree());
	NOGBA("vs mem free : %dko (%do)",oldv/1024,oldv);

	levelInfoCounter=60;
}