Surface::Surface(Seed seed){ this->seed = seed; // TODO: DENSITY switch (seed.getSurfaceShape()){ case Seed::SPHERE: rawShape = ofSpherePrimitive(seed.shapeSize, 64); break; case Seed::PLANE: rawShape = ofPlanePrimitive(seed.shapeSize, seed.shapeSize, seed.numCols, seed.numCols); // rawShape =ofBoxPrimitive(seed.shapeSize, seed.shapeSize, seed.shapeSize); break; default: rawShape = ofSpherePrimitive(1,1); } if ((seed.numCols % 2) != 0){ even = false; } else even = true; vboMesh = rawShape.getMesh(); };
//-------------------------------------------------------------- void ofApp::update(){ glPointSize(three); myMesh = ofSpherePrimitive(1000, two).getMesh(); myMesh.setMode(OF_PRIMITIVE_POINTS); ofSetColor(255, 0, 0); myMesh02 = ofSpherePrimitive(80, two).getMesh(); myMesh02.setMode(OF_PRIMITIVE_LINES); for (int i = 0; i < myMesh.getVertices().size(); i++) { ofVec3f loc = myMesh.getVertices()[i] / 100; float noise = ofMap(ofNoise(loc.x, loc.y, loc.z, ofGetElapsedTimef()), 0, 1, 80, one); ofVec3f newLoc = loc.normalize() * noise; myMesh.setVertex(i, newLoc); } for (int i = 0; i < myMesh02.getVertices().size(); i++) { ofVec3f loc = myMesh02.getVertices()[i] / 100; float noise = ofMap(ofNoise(loc.x, loc.y, loc.z, ofGetElapsedTimef()), 0, 1, 80, 100); ofVec3f newLoc = loc.normalize() * noise; myMesh02.setVertex(i, newLoc); } }
void ofxPBR::setup(function<void()> scene, ofCamera* camera, int depthMapResolution) { this->scene = scene; this->camera = camera; sphereMesh = ofSpherePrimitive(1, 100).getMesh(); for (int i = 0; i<sphereMesh.getNormals().size(); i++) { sphereMesh.setNormal(i, ofVec3f(1.0, 1.0, -1.0) * glm::normalize(sphereMesh.getVertex(i))); } spotShadow.setup(4, depthMapResolution); omniShadow.setup(1, depthMapResolution); directionalShadow.setup(1, depthMapResolution); directionalShadow.setBoundingBox(0, 0, 0, 1000, 1000, 1000); renderMode = Mode_PBR; // load env shader envShader = new ofShader(); envShader->setupShaderFromSource(GL_VERTEX_SHADER, environmentShaderSource.gl3VertShader); envShader->setupShaderFromSource(GL_FRAGMENT_SHADER, environmentShaderSource.gl3FragShader); envShader->bindDefaults(); envShader->linkProgram(); // load defalut pbr shader defaultShader = ofShader(); defaultShader.setupShaderFromSource(GL_VERTEX_SHADER, pbrShaderSource.gl3VertShader); defaultShader.setupShaderFromSource(GL_FRAGMENT_SHADER, pbrShaderSource.gl3FragShader); defaultShader.bindDefaults(); defaultShader.linkProgram(); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetVerticalSync(true); ofDisableArbTex(); // Thetaの設定(USB接続) devices = theta.listDevices(); bool isDeviceConnected = false; for(int i = 0; i < devices.size(); i++){ if(devices[i].deviceName == "RICOH THETA S"){ theta.setDeviceID(devices[i].id); isDeviceConnected = true; maxSource = 3; } } if(!isDeviceConnected){ ofLog(OF_LOG_ERROR, "RICOH THETA S is not connected."); maxSource = 2; } theta.initGrabber(1280, 720); // 環境マップ用の静止画 envImage.load("wadabori_park.jpg"); // 環境マップ用の動画 videoPlayer.load("ohmiya_shrine.mp4"); videoPlayer.setLoopState(OF_LOOP_NORMAL); // 3Dモデル model.loadModel("dragon.obj"); modelScale = model.getModelMatrix().getScale(); // Dual fish-eyeからEquirectangularに変換するシェーダー equirectShader.load("shaders/equirectanguler"); // 環境マップ用のシェーダー envMapShader.load("shaders/equirectEnvMap"); // 背景用のPrimitive Sphere envSphere = ofSpherePrimitive(2000, 64).getMesh(); for(int i=0;i<envSphere.getNumTexCoords();i++){ envSphere.setTexCoord(i, ofVec2f(1.0) - envSphere.getTexCoord(i)); } for(int i=0;i<envSphere.getNumNormals();i++){ envSphere.setNormal(i, envSphere.getNormal(i) * ofVec3f(-1)); } // 変換後の動画書き込みに使用するFBO fbo.allocate(1920, 1080); // 環境マップの素材 source = 0; // 3Dオブジェクト object = 0; }
void StFftSphereStripe::createMesh(){ mesh = ofSpherePrimitive(ofGetWidth(), 48).getMesh(); for (int i = 0; i < mesh.getVertices().size(); i++) { ofVec2f texCoord = mesh.getTexCoord(i); texCoord.x *= tex.getWidth(); texCoord.y = (1.0 - texCoord.y) * tex.getHeight(); mesh.setTexCoord(i, texCoord); currentVertex.push_back(ofVec3f(mesh.getVertices()[i].x, mesh.getVertices()[i].y, mesh.getVertices()[i].z)); } }
ofxIBL::ofxIBL(){ IBLShader.setupShaderFromSource(GL_VERTEX_SHADER, iblShaderStrings.gl3VertShader); IBLShader.setupShaderFromSource(GL_FRAGMENT_SHADER, iblShaderStrings.gl3FragShader); IBLShader.bindDefaults(); IBLShader.linkProgram(); sphereMesh = ofSpherePrimitive(1, 100).getMesh(); for(int i=0;i<sphereMesh.getNormals().size();i++){ sphereMesh.setNormal(i, ofVec3f(1.0, 1.0, -1.0) * sphereMesh.getVertex(i).normalize()); } }
Particles::Particles(int _maxParticles){ maxParticles = _maxParticles; numParticles = 0; friction = 0.01; //mesh.setMode(OF_PRIMITIVE_POINTS); mesh = ofSpherePrimitive(200, 72).getMesh(); for (int i = 0; i < mesh.getVertices().size(); i++) { mesh.addColor(ofFloatColor(1.0, 1.0, 1.0, 1.0)); } }
//-------------------------------------------------------------- void Lighting::setup() { ENTROPY_SCENE_EXIT_LISTENER; ENTROPY_SCENE_RESIZE_LISTENER; ENTROPY_SCENE_UPDATE_LISTENER; ENTROPY_SCENE_DRAW_WORLD_LISTENER; ENTROPY_SCENE_GUI_LISTENER; // Load shaders. this->shader.load("shaders/main"); this->shader.printActiveUniforms(); this->shader.printActiveUniformBlocks(); CheckGLError(); this->skyboxShader.load("shaders/skybox"); glGenVertexArrays(1, &this->defaultVao); CheckGLError(); // Set up view UBO. const int viewUboBinding = 1; this->viewUbo.setup(viewUboBinding); this->viewUbo.configureShader(this->shader); this->viewUbo.configureShader(this->skyboxShader); CheckGLError(); // Set up lighting. this->lightingSystem.setup(this->getCamera()); this->lightingSystem.configureShader(this->shader); this->lightingSystem.setAmbientIntensity(0.5f); CheckGLError(); // Set up PBR. this->material.setBaseColor(ofFloatColor(1.0f, 1.0f, 1.0f, 1.0f)); this->material.setMetallic(0.0f); this->material.setRoughness(0.0f); this->material.setEmissiveColor(ofFloatColor(1.0f, 0.4f, 0.0f, 1.0f)); this->material.setEmissiveIntensity(0.0f); CheckGLError(); this->skyboxMap.loadDDSTexture("textures/output_skybox.dds"); this->irradianceMap.loadDDSTexture("textures/output_iem.dds"); this->radianceMap.loadDDSTexture("textures/output_pmrem.dds"); CheckGLError(); glEnable(GL_TEXTURE_CUBE_MAP_SEAMLESS); this->sphere = ofSpherePrimitive(1.0f, 24); }
//-------------------------------------------------------------- void ofApp::setup(){ ofSetFrameRate(60); //ofSetBackgroundAuto(false); ofBackground(0); //ofEnableDepthTest(); light.enable(); light.setPosition(-100, 100, 500); myMesh = ofSpherePrimitive(200,72).getMesh(); for (int i=0; i<myMesh.getVertices().size(); i++) { myMesh.addColor(ofFloatColor(1.0,1.0,1.0,1.0)); } width = ofGetWidth(); height = ofGetHeight(); myImage.allocate(ofGetWidth(), ofGetHeight(), OF_IMAGE_GRAYSCALE); pixels = myImage.getPixels(); particleNum = 10; particles = new Particles(particleNum); for (int i = 0; i < particleNum; i++) { ofVec3f position = ofVec3f(ofRandom(width), ofRandom(height)); particles->addParticle(position); } for (int j = 0; j < height; j++) { for (int i = 0; i < width; i++) { float noiseX = ofMap(i, 0, width, 0, scaleX); float noiseY = ofMap(j, 0, width, 0, scaleY); int noiseVal = ofNoise(noiseX, noiseY) * 255; pixels[j * width + i] = noiseVal; } } myImage.update(); scaleX.addListener(this, &ofApp::scaleXChanged); scaleY.addListener(this, &ofApp::scaleYChanged); gui.setup(); gui.add(speed.setup("speed", 0.1, 0.0, 0.5)); gui.add(friction.setup("friction", 0.01, 0.0, 0.04)); gui.add(scaleX.setup("scale x", 5.0, 1.0, 10.0)); gui.add(scaleY.setup("scale y", 5.0, 1.0, 10.0)); }
MyMesh::MyMesh(float _zone_focus, float _zone_calm, float _zone_posture) { zone_focus = _zone_focus; zone_calm = _zone_calm; zone_posture = _zone_posture; //初期位置を画面の中心に pos.x = 0; pos.y = 0; //球からメッシュを生成 meshA = ofSpherePrimitive(100, 50).getMesh(); //メッシュの色を設定 for (int i = 0; i < meshA.getVertices().size(); i++) { meshA.addColor(ofFloatColor(1.0, 1.0, 1.0, 1.0)); } }
void StFftSphereRibbon::createMesh(){ mesh = ofSpherePrimitive(5, 8).getMesh(); for (int i = 0; i < mesh.getVertices().size(); i++) { ofVec2f texCoord = mesh.getTexCoord(i); currentVertex.push_back(ofVec3f(mesh.getVertices()[i].x, mesh.getVertices()[i].y, mesh.getVertices()[i].z)); interplateVertex.push_back(currentVertex[currentVertex.size()-1]); randomVec.push_back(ofVec3f(ofRandom(-1, 1),ofRandom(-1, 1),ofRandom(-1, 1))); int hue = ofMap(i, 0, mesh.getVertices().size()-1, 0, 80); ofColor col; col.setHsb(hue, 180, 127); ofxTwistedRibbon *r = new ofxTwistedRibbon(); r->length = 40; r->thickness = 4; r->color = col; ribbons.push_back(r); } mesh.setMode(OF_PRIMITIVE_POINTS); }
//-------------------------------------------------------------- void ofApp::update(){ myFbo.begin(); ofClear(0, 0, 0, 0); ofPushMatrix(); ofTranslate(ofGetWidth()/2,ofGetHeight()/2); ofRotateZ(-35); ofSetColor(0, 0, 255); ofRect(-120, -120, 240, 240); ofRotateZ(35); ofRotateZ(25); ofSetColor(255, 0, 0); ofRect(-40, -40, 80, 80); ofRotateZ(-25); ofSetColor(255); ofTranslate(0, -150); ofSpherePrimitive(100.f, 3).getMesh().drawWireframe(); ofPopMatrix(); myFbo.end(); myAAFbo.begin(); ofClear(0, 0, 0, 0); if (enableAA) { fxaa.begin(); } myFbo.draw(ofVec2f(0,0)); if (enableAA) { fxaa.end(); } myAAFbo.end(); }
void form::draw() { for (int i=0; i<mParticles.size();i++) { mMesh.setVertex(i, mParticles[i]->getPosition()); mOuterMesh.setVertex(i, mBottomParticles[i]->getPosition()); } glEnable( GL_DEPTH_TEST ); mCamera.begin(ofRectangle(ofGetHeight(), 0, ofGetHeight(), ofGetHeight())); ofSetColor(255,0,128); ofEnableLighting(); ofSetColor(255, 255, 255); mLight.enable(); mLight.setPosition(ofVec3f(30, -15+5, -1)); mLight.setAttenuation(0.75,0,0); ofSetColor(185, 185, 185); for(int i=0; i<mBounds.size();i++) { mBounds[i]->draw(); } ofDisableAlphaBlending(); ofDisableBlendMode(); ofSetColor(255, 0, 128); ofMaterial meshmat; meshmat.setColors(ofColor(255,0,128), ofColor(255,0,128), ofColor(100,0,60), ofColor(0,0,0)); meshmat.setShininess(0.5); meshmat.begin(); mMesh.ofMesh::draw(OF_MESH_FILL); mOuterMesh.ofMesh::draw(OF_MESH_FILL); for (int i=1; i<mMasterEdgeParticles.size();i++) { ofBeginShape(); ofVertex((ofPoint &)mBottomParticles[mMasterEdgeParticles[i-1]->array_ind]->getPosition()); ofVertex((ofPoint &)mBottomParticles[mMasterEdgeParticles[i]->array_ind]->getPosition()); ofVertex((ofPoint &)mParticles[mMasterEdgeParticles[i]->array_ind]->getPosition()); ofVertex((ofPoint &)mParticles[mMasterEdgeParticles[i-1]->array_ind]->getPosition()); ofEndShape(); } for (int i=1; i<mSlaveEdgeParticles.size();i++) { ofBeginShape(); ofVertex((ofPoint &)mBottomParticles[mSlaveEdgeParticles[i-1]->array_ind]->getPosition()); ofVertex((ofPoint &)mBottomParticles[mSlaveEdgeParticles[i]->array_ind]->getPosition()); ofVertex((ofPoint &)mParticles[mSlaveEdgeParticles[i]->array_ind]->getPosition()); ofVertex((ofPoint &)mParticles[mSlaveEdgeParticles[i-1]->array_ind]->getPosition()); ofEndShape(); } meshmat.end(); mLight.disable(); ofDisableLighting(); if (mMasterEdgeParticles.size()>0) { part_and_index *pai = mMasterEdgeParticles[0]; //for (auto pai : mMasterEdgeParticles) { ofPushMatrix(); ofTranslate(pai->part->getPosition()); ofSpherePrimitive(3, 5).draw(); ofPopMatrix(); //} pai = mSlaveEdgeParticles[0]; //for (auto pai : mSlaveEdgeParticles) { ofPushMatrix(); ofTranslate(pai->part->getPosition()); ofSpherePrimitive(3, 5).draw(); ofPopMatrix(); //} } ofSetColor(255,255,255); for (int i=0; i<mAtZip;i++) { if (i < mZipperSprings.size()) { ofLine(mZipperSprings[i]->getOneEnd()->getPosition(),mZipperSprings[i]->getTheOtherEnd()->getPosition()); } } /*ofSetColor(255,0,255); for (int i=0; i<mMiddleSprings.size();i++) { ofLine(mMiddleSprings[i]->getOneEnd()->getPosition(),mMiddleSprings[i]->getTheOtherEnd()->getPosition()); }*/ mCamera.end(); glDisable(GL_DEPTH_TEST); }
//-------------------------------------------------------------- void ofApp::draw3d(){ //ofEnableDepthTest(); points.clear(); sizes.clear(); points2.clear(); sizes2.clear(); //カメラ設定 int cx,cy; cameraCount++; cameraMoving = ofVec3f(0,objRoad.count*objRoad.speed,0); camera2.setPosition(camera.getPosition()+cameraMoving); camera2.lookAt(cameraMoving,ofVec3f(0,0,1)); switch (cameraId) { case 1: camera.setPosition(0, -1000, 400); camera.lookAt(ofVec3f(0,0,0),ofVec3f(0,0,1)); break; case 2: camera.setPosition(800, -800, 300); //camera.setPosition(1500, -3000, 800); camera.lookAt(ofVec3f(0,0,0),ofVec3f(0,0,1)); break; case 3: camera.setPosition(0, 1500, 500); camera.lookAt(ofVec3f(0,0,0),ofVec3f(0,0,1)); break; case 4: cx = 1200*cos( cameraCount/200.0 ); cy = 1200*sin( cameraCount/200.0 ); camera.setPosition(cx, cy, 400); camera.lookAt(ofVec3f(0,0,0),ofVec3f(0,0,1)); break; case 5: cx = -1200*cos( cameraCount/100.0 )*(cos(cameraCount/100.0)+2)/3; cy = 1200*sin( cameraCount/100.0 )*(cos(cameraCount/100.0)+2)/3; camera.setPosition(cx, cy, 400*(cos(cameraCount/100.0)+2)/3); camera.lookAt(ofVec3f(0,0,0),ofVec3f(0,0,1)); break; default: break; } glDepthMask(GL_FALSE);//デプスバッファに書き込むのを禁止する ofEnableBlendMode(OF_BLENDMODE_ADD);//加算描画 this makes everything look glowy ofEnablePointSprites(); //道路表示 //shader2.begin(); camera2.begin(); ofVec4f bufpos,bufpos_1f; for(int i=objRoad.getIdxStart();i<objRoad.getIdxEnd();i++){ bufpos = objRoad.getLeftPos(i); int roadwidth = objRoad.getRoadWidth(i); if(i==objRoad.getIdxStart()){ continue; } //ofSetColor(rainbow[(i/10)%7][0],rainbow[(i/10)%7][1],rainbow[(i/10)%7][2],bufpos.w); ofSetColor(0,200,0,bufpos.w); ofBoxPrimitive buf_box; buf_box = ofBoxPrimitive(roadwidth, objRoad.width, 1); buf_box.setPosition(bufpos_1f.x, bufpos_1f.y+objRoad.width/2, bufpos.z); buf_box.draw(); if(i%20==0){ ofSetColor(255,0,0,255); ofSpherePrimitive a; a = ofSpherePrimitive(10, 20); a.setPosition(bufpos_1f.x, bufpos_1f.y, 0); a.draw(); ofBoxPrimitive b; b = ofBoxPrimitive(roadwidth, 3, 20); b.setPosition(bufpos_1f.x, bufpos_1f.y, bufpos.z); b.draw(); } bufpos_1f = bufpos; } camera2.end(); //shader2.end(); ofDisablePointSprites(); ofDisableBlendMode(); glDepthMask(GL_TRUE); //観客描画 //ofEnableBlendMode(OF_BLENDMODE_ADD);//加算描画 this makes everything look glowy if(bDraw3d){ int buf_x,buf_y,buf_z,buf_speed; for (int i = 0; i < ObjHumans.size(); i++) { buf_x = ObjHumans[i].position.x; buf_x = ((buf_x - 512 - objFrameOffsetx)*scalex)>>5; //32等倍 buf_y = ObjHumans[i].position.y; buf_y = ((buf_y - 512 - objFrameOffsety)*scaley)>>5; //32等倍 buf_z = (ObjHumans[i].positionz * scalez) >>5;//32等倍 buf_speed = (int)(ObjHumans[i].speed*humanscale/50+humansizeoffset); if(ObjHumans[i].humanStd <= ObjHumans[i].objMissThr){ if(ObjHumans[i].humanStd>=0){ addPoint(buf_x, buf_y, buf_z,buf_speed*2); } addPoint(buf_x, buf_y, buf_z,buf_speed*2); boxScale.push_back(buf_speed); }else{ addPoint2(buf_x, buf_y, buf_z,buf_speed*2); boxScale2.push_back(buf_speed); } } } glDepthMask(GL_FALSE); // this makes everything look glowy :) ofEnablePointSprites(); //ofEnableBlendMode(OF_BLENDMODE_ADD); ofEnableAlphaBlending(); shader.begin(); camera.begin(); glPointSize(20); //観客ノード texture.bind(); //texture2.bind(); //ofSetColor(255); ofSetColor(0, 100, 255); int total = (int)points.size(); vbo.setVertexData(&points[0], total, GL_STATIC_DRAW); vbo.setNormalData(&sizes[0], total, GL_STATIC_DRAW); vbo.draw(GL_POINTS, 0, (int)points.size()); ofSetColor(255, 100, 90); total = (int)points2.size(); vbo.setVertexData(&points2[0], total, GL_STATIC_DRAW); vbo.setNormalData(&sizes2[0], total, GL_STATIC_DRAW); vbo.draw(GL_POINTS, 0,(int)points2.size()); texture.unbind(); //texture2.unbind(); //ライブハウスグリッド描画 objFrame.draw(); camera.end(); shader.end(); ofDisablePointSprites(); //ofDisableBlendMode(); ofDisableAlphaBlending(); //基準座標 camera2.begin(); ofSetLineWidth(1); /*ofSetColor(255,0,0); ofLine(ofVec3f(0,0,0), ofVec3f(300,0,0)); ofSetColor(0,255,0); ofLine(ofVec3f(0,0,0), ofVec3f(0,300,0)); ofSetColor(0,0,255); ofLine(ofVec3f(0,0,0), ofVec3f(0,0,300));*/ //ここから松 ofEnableAlphaBlending(); // bind the shader so that wee can change the // size of the points via the vert shader billboardShader.begin(); ofEnablePointSprites(); // not needed for GL3/4 texture_.getTextureReference().bind(); billboards.draw(); texture_.getTextureReference().unbind(); ofDisablePointSprites(); // not needed for GL3/4 billboardShader.end(); ofDisableAlphaBlending(); //ここまで松 camera2.end(); /*float boxSize = 100; ofFill(); ofSetColor(255); ofDrawBox(boxSize); ofNoFill();*/ //ba.drawNormals(1000); //texture3.getTextureReference().unbind(); ofEnableAlphaBlending(); camera2.begin(); objTorii.draw(texTorii); for(int i =0 ;i< objClouds.size();i++){ if(objClouds[i].visible(cameraMoving.y)){ objClouds[i].draw(texCloud); } } for(int i =0 ;i< objLibs.size();i++){ if(objLibs[i].visible(cameraMoving.y)){ objLibs[i].draw(texLibs[objLibs[i].texidi*TEXLIBNUM+objLibs[i].texidj]); }else{ if(objLibs[i].killmyself(cameraMoving.y)){ objLibs.erase(objLibs.begin()+i); } } } camera2.end(); //ここから応援コメント camera.begin(); ofSetColor(255,255,255); for (int i = 0; i < 3 ;i++){ for(int j = 0;j < 2; j++){ for(int k =0; k < 2; k++){ if(commentdraw[i][j][k]){ objTexts[i*4+j*2+k].draw(texTexts[i*4+j*2+k]); } } } } camera.end(); ofDisableAlphaBlending(); glDepthMask(GL_TRUE); }