static void drawShockwaves(float radius) { int waves; glColor3f(1,0,0); for(waves = 0; waves < NUM_SHOCKWAVES; waves++) { if (radius > SHOCKWAVE_MIN_RADIUS && radius < SHOCKWAVE_MAX_RADIUS) { drawWave(radius); } radius -= SHOCKWAVE_SPACING; } }
void SceneWave::draw() { ofNoFill(); for (int i = 0; i < NUM_SAMPLES; i++) { mCol.setHue(ofMap(i, 0, NUM_SAMPLES, 0, 255)); ofSetColor(mCol); drawWave(mSamples[i]); } }
int main() { int i; int mouseX, mouseY; waveStruct waves[maxWaves]; int wavesCount = 0; int drawWaves; double buildTime = glfwGetTime(); glfwInit(); glfwOpenWindowHint(GLFW_FSAA_SAMPLES,8); glfwOpenWindow(xSize, ySize, 0, 0, 0, 0, 24, 0, GLFW_WINDOW); glfwSetWindowPos(0, 0); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho(0, xSize, 0, ySize, 0, 1); glMatrixMode(GL_MODELVIEW); glDisable(GL_DEPTH_TEST); glfwSwapInterval(1); while(1) { glClear(GL_COLOR_BUFFER_BIT); getFps(); if(currentTime - buildTime > 0.48) { buildTime = glfwGetTime(); glfwGetMousePos(&mouseX,&mouseY); buildWave(waves, &wavesCount, mouseX, mouseY); } drawWaves = (wavesCount >= maxWaves) ? maxWaves : wavesCount; for(i = 0; i < drawWaves; ++i) { drawWave(waves[i]); waves[i].radius += 0.032 * (1024/FPS); } glfwSwapBuffers(); } return 0; }
/* first we see if we even need to draw by checking if it is in the camera, via cameraGetLoc() cameraGetLoc() returns a drawable rect (if camera is zoomed it needs to translate) which draw can use. DRAW SHOULD NEVER AFFECT GAME WORLD */ void drawObject(dioneObject *obj) { SDL_Rect drawable; SDL_bool in_camera; in_camera = cameraGetLoc(&(obj->l), &drawable); if (in_camera == SDL_FALSE) { return; } /* drawable is now in pixels not world units. We can just draw it like it is! */ switch (TYPEOF(obj)) { case OBJ_LINE: drawLine((lineObject*)obj, &drawable); break; case OBJ_PEOPLE: drawPerson((humanObject*)obj, &drawable); break; case OBJ_WAVE: drawWave((waveObject*)obj, &drawable); break; case OBJ_CUSTOM: (((customObject*)obj)->drawFunc)(obj); break; case OBJ_POLY: drawPoly((polyObject*)obj, &drawable); break; case OBJ_BEZIER: drawBezier((bezierObject*)obj, &drawable); break; case OBJ_TEXTURE: drawTexture((textureObject*)obj, &drawable); break; case OBJ_TEXT: drawText((textObject*)obj, &drawable); break; default: /* I never want to be here */ print_message(MSG_VERBOSE_ERROR, MSG_FLAG_NONE, "[draw] I have no idea how to handle this obj: %x!", obj); } }
void MainWindow::createActions() /*菜单选项*/ { /*文件菜单*/ openAction = new QAction(tr("打开"),this); openAction->setStatusTip(tr("打开新文件")); connect(openAction,SIGNAL(triggered()),this,SLOT(openFile())); importAction = new QAction(tr("导入"),this); importAction->setStatusTip(tr("导入数据")); connect(importAction,SIGNAL(triggered()),this,SLOT(importFile())); importAction->setDisabled(true); sortAction = new QAction(tr("分类数据"),this); sortAction->setStatusTip(tr("处理分类数据")); connect(sortAction,SIGNAL(triggered()),this,SLOT(sortFile())); sortAction->setDisabled(true); exitAction = new QAction(tr("退出"),this); exitAction->setStatusTip(tr("退出程序")); connect(exitAction,SIGNAL(triggered()),this,SLOT(close())); /*导入菜单*/ ebdicAction = new QAction(tr("显示EBDIC码"),this); ebdicAction->setStatusTip(tr("显示EBDIC码")); connect(ebdicAction,SIGNAL(triggered()),this,SLOT(loadEBDIC())); ebdicAction->setDisabled(true); reelAction = new QAction(tr("显示卷头"),this); reelAction->setStatusTip(tr("显示卷头信息")); connect(reelAction,SIGNAL(triggered()),this,SLOT(loadReel())); reelAction->setDisabled(true); traceAction = new QAction(tr("显示道头"),this); traceAction->setStatusTip(tr("显示选定位置道头信息")); connect(traceAction,SIGNAL(triggered()),this,SLOT(loadTrace())); traceAction->setDisabled(true); dataAction = new QAction(tr("地震数据"),this); dataAction->setStatusTip(tr("显示选定位置的地震记录")); connect(dataAction,SIGNAL(triggered()),this,SLOT(loadData())); dataAction->setDisabled(true); /*画图菜单*/ waveAction = new QAction(tr("波形显示"),this); waveAction->setStatusTip(tr("波形显示剖面")); connect(waveAction,SIGNAL(triggered()),this,SLOT(drawWave())); waveAction->setDisabled(true); grayAction = new QAction(tr("灰度显示"),this); grayAction->setStatusTip(tr("显示灰度图像")); connect(grayAction,SIGNAL(triggered()),this,SLOT(drawGray())); grayAction->setDisabled(true); colorAction = new QAction(tr("彩色显示"),this); colorAction->setStatusTip(tr("显示彩色图像")); connect(colorAction,SIGNAL(triggered()),this,SLOT(drawColor())); colorAction->setDisabled(true); //操作openGL图像 bigAction = new QAction(tr("放大"),this); bigAction->setStatusTip(tr("放大图像")); connect(bigAction,SIGNAL(triggered()),this,SLOT(bigger())); bigAction->setDisabled(true); littleAction = new QAction(tr("缩小"),this); littleAction->setStatusTip(tr("缩小图像")); connect(littleAction,SIGNAL(triggered()),this,SLOT(little())); littleAction->setDisabled(true); moveleftAction = new QAction(tr("左移"),this); moveleftAction->setStatusTip(tr("左移图像")); connect(moveleftAction,SIGNAL(triggered()),this,SLOT(moveleft())); moveleftAction->setDisabled(true); moverightAction = new QAction(tr("右移"),this); moverightAction->setStatusTip(tr("图像右移")); connect(moverightAction,SIGNAL(triggered()),this,SLOT(moveright())); moverightAction->setDisabled(true); moveupAction = new QAction(tr("上移"),this); moveupAction->setStatusTip(tr("上移图像")); connect(moveupAction,SIGNAL(triggered()),this,SLOT(moveup())); moveupAction->setDisabled(true); movedownAction = new QAction(tr("下移"),this); movedownAction->setStatusTip(tr("下移图像")); connect(movedownAction,SIGNAL(triggered()),this,SLOT(movedown())); movedownAction->setDisabled(true); moveMouseAction = new QAction(tr("移动"),this); moveMouseAction->setStatusTip(tr("使用鼠标移动图像")); connect(moveMouseAction,SIGNAL(triggered()),this,SLOT(moveMouse())); moveMouseAction->setDisabled(true); rotateMouseAction = new QAction(tr("旋转"),this); rotateMouseAction->setStatusTip(tr("旋转图像")); connect(rotateMouseAction,SIGNAL(triggered()),this,SLOT(rotateMouse())); rotateMouseAction->setDisabled(true); nextSliceAction = new QAction(tr("下一条剖面"),this); nextSliceAction->setStatusTip(tr("选择下一条剖面")); connect(nextSliceAction,SIGNAL(triggered()),this,SLOT(nextSlice())); nextSliceAction->setDisabled(true); preSliceAction = new QAction(tr("上一条剖面"),this); preSliceAction->setStatusTip(tr("选择上一条剖面")); connect(preSliceAction,SIGNAL(triggered()),this,SLOT(preSlice())); preSliceAction->setDisabled(true); drawGridAction = new QAction(tr("关闭网格"),this); drawGridAction->setStatusTip(tr("打开/关闭剖面图像上的网格")); connect(drawGridAction,SIGNAL(triggered()),this,SLOT(drawGrid())); drawGridAction->setDisabled(true); }
//-------------------------------------------------------------- void ofApp::draw(){ drawWave(); sendNoise(); }
void display(void) { //時間計測 curTime = timeGetTime(); float dt = (float)(curTime - lastTime) * 0.001;//secに変換 elapseTime1 += dt; elapseTime2 += dt; fps ++; printf("elapseTime2 = %f \n", elapseTime2); if(elapseTime1 >= 1.0) { printf("frame per sec = %d \n", fps); elapseTime1 = 0.0; fps = 0; } lastTime = curTime; //波データを作成し、投影マップを設定 if(kindWave == 0) makeWaveCircle(amp, elapseTime2); else if(kindWave == 1) makeWavePlane(amp, elapseTime2); else makeWaveMix(amp, elapseTime2); makeTexImage(); setTexture(); if(flagWireframe)//'w'でwireframeとsolid model切り替え { glPolygonMode(GL_FRONT,GL_LINE); glPolygonMode(GL_BACK,GL_POINT); } else glPolygonMode(GL_FRONT_AND_BACK,GL_FILL); resize(width, height); //カラーバッファのクリア glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); if(cos(M_PI * view.theta /180.0) > 0.0)//カメラ仰角90度でビューアップベクトル切替 gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, 1.0, 0.0); else gluLookAt(view.pos[0], view.pos[1], view.pos[2], view.cnt[0], view.cnt[1], view.cnt[2], 0.0, -1.0, 0.0); //光源設定//'l'を押した後光源位置可変 glLightfv(GL_LIGHT0, GL_POSITION, lightPos); //fragment shaderのユニフォーム変数インデックスを取得 GLint texLoc = glGetUniformLocation(shaderProg, "smplCaustics"); glUniform1i(texLoc, 0);//GL_TEXTURE0を適用 // シェーダプログラムの適用 glUseProgram(shaderProg); //描画 fish1.motion1(elapseTime2); fish2.motion1(elapseTime2); drawFloor0(10.0, 10.0, 10, 10); // シェーダプログラムの適用を解除 glUseProgram(0); //テクスチャ、半透明物体があるとき glDepthMask(GL_FALSE); //デプスバッファを書き込み禁止 glEnable(GL_BLEND);//アルファブレンディングを有効にする glBlendFunc(GL_DST_ALPHA,GL_ONE_MINUS_SRC_ALPHA);//色混合係数を決める //半透明描画 drawWave(); //テクスチャ、半透明物体があるとき glDepthMask(GL_TRUE); //デプスバッファの書き込みを許可 glDisable(GL_BLEND); //影 drawShadow(); drawLight(); if(flagHelp) { printf("矢印キーによる光源/投影中心移動 \n"); printf(" →,←:x軸 \n"); printf(" ↑,↓:y軸 \n"); printf(" [Shift]+↑,↓:z軸 \n"); printf(" 'l'を押した後、光源位置の移動可 \n"); printf("'w'でワイヤーフレームとソリッドモデル切り替え \n"); printf("マウス操作で視点変更可 \n"); printf(" dolly:中央付近を左ボタンクリックで近づき,右ボタンクリックで遠ざかる \n"); printf(" pan:左横および右横を右ボタンクリックで注視点が左右に変化する \n"); printf(" tilt:真上および真下を右ボタンクリックで注視点が上下に変化する \n"); printf(" tumble:左右にドラッグすると視点が左右に変化する \n"); printf(" crane:上下にドラッグすると視点が上下に変化する \n"); printf(" zoom:左下を右ボタンクリックでズームイン \n"); printf(" 右下を右ボタンクリックでズームアウト \n"); printf("[Shift]+'r'でリセット \n"); printf("[F1]キー:投影マッピングの視野角fovの増減 \n"); printf("[F2]キー:波の振幅amp \n"); printf("[F3]キー:波の種類(円形波と平面波)の切り替え \n"); printf("[F4]キー:円形波の個数切り替え \n"); flagHelp = false; } //終了 glutSwapBuffers(); }