void Mesh3DDecorated::recomputeMeanNormals() { switchNormals(true); normalCoords.clear(); normalId.clear(); /* We don't need this, just normalise */ vector<int> counts; normalCoords.resize(vertexes.size(), Vector3dd::Zero()); counts.resize(vertexes.size(), 0 ); for (size_t f = 0; f < faces.size(); f++) { Triangle3dd triangle = getFaceAsTrinagle(f); Vector3dd normal = triangle.getNormal(); for (int c = 0; c < 3; c++) { int vertexId = faces[f][c]; normalCoords[vertexId] += normal; counts[vertexId] ++; } normalId.push_back(faces[f]); } for (size_t n = 0; n < normalCoords.size(); n++) { normalCoords[n] /= counts[n]; normalCoords[n].normalise(); } }
bool frameRenderingQueued(const FrameEvent& evt) { if( ExampleFrameListener::frameRenderingQueued(evt) == false ) { // check if we are exiting, if so, clear static HardwareBuffers to avoid segfault WaterCircle::clearStaticBuffers(); return false; } mAnimState->addTime(evt.timeSinceLastFrame); // process keyboard events Real changeSpeed = evt.timeSinceLastFrame ; // adjust keyboard speed with SHIFT (increase) and CONTROL (decrease) if (mKeyboard->isKeyDown(OIS::KC_LSHIFT) || mKeyboard->isKeyDown(OIS::KC_RSHIFT)) { changeSpeed *= 10.0f ; } if (mKeyboard->isKeyDown(OIS::KC_LCONTROL)) { changeSpeed /= 10.0f ; } // rain processCircles(evt.timeSinceLastFrame); if (mKeyboard->isKeyDown(OIS::KC_SPACE)) { particleEmitter->setEmissionRate(20.0f); } else { particleEmitter->setEmissionRate(0.0f); } processParticles(); // adjust values (some macros for faster change #define ADJUST_RANGE(_value,_plus,_minus,_minVal,_maxVal,_change,_macro) {\ if (mKeyboard->isKeyDown(_plus)) \ { _value+=_change ; if (_value>=_maxVal) _value = _maxVal ; _macro ; } ; \ if (mKeyboard->isKeyDown(_minus)) \ { _value-=_change; if (_value<=_minVal) _value = _minVal ; _macro ; } ; \ } ADJUST_RANGE(headDepth, OIS::KC_U, OIS::KC_J, 0, 10, 0.5*changeSpeed, updateInfoHeadDepth()) ; ADJUST_RANGE(waterMesh->PARAM_C, OIS::KC_2, OIS::KC_1, 0, 10, 0.1f*changeSpeed, updateInfoParamC()) ; ADJUST_RANGE(waterMesh->PARAM_D, OIS::KC_4, OIS::KC_3, 0.1, 10, 0.1f*changeSpeed, updateInfoParamD()) ; ADJUST_RANGE(waterMesh->PARAM_U, OIS::KC_6, OIS::KC_5, -2, 10, 0.1f*changeSpeed, updateInfoParamU()) ; ADJUST_RANGE(waterMesh->PARAM_T, OIS::KC_8, OIS::KC_7, 0, 10, 0.1f*changeSpeed, updateInfoParamT()) ; timeoutDelay-=evt.timeSinceLastFrame ; if (timeoutDelay<=0) timeoutDelay = 0; #define SWITCH_VALUE(_key,_timeDelay, _macro) { \ if (mKeyboard->isKeyDown(_key) && timeoutDelay==0) { \ timeoutDelay = _timeDelay ; _macro ;} } SWITCH_VALUE(OIS::KC_N, 0.5f, switchNormals()); SWITCH_VALUE(OIS::KC_M, 0.5f, switchMaterial()); SWITCH_VALUE(OIS::KC_B, 0.5f, switchSkyBox()); animateHead(evt.timeSinceLastFrame); waterMesh->updateMesh(evt.timeSinceLastFrame); return true; }