void ProcessNormalKeys(unsigned char key, int x, int y) { if (key == 27) exit(0); else if (key == ' ') { g_camera.m_angleX = 0.0f; g_camera.m_angleY = 0.0f; g_camera.m_zoom = 10.0f; } else if (key == 'r') { ResetSimulation(); } else if (key == 'w') { g_sphere.m_center.z += 0.1f; } else if (key == 's') { g_sphere.m_center.z -= 0.1f; } else if (key == 'a') { g_sphere.m_center.y += 0.1f; } else if (key == 'd') { g_sphere.m_center.y -= 0.1f; } }
void CQTOpenGLMainWindow::CreateConnections() { /* Play/pause button pressed */ connect(m_pcPlayAction, SIGNAL(triggered(bool)), m_pcOpenGLWidget, SLOT(PlayPauseSimulation(bool))); /* Step button pressed */ connect(m_pcStepAction, SIGNAL(triggered()), m_pcOpenGLWidget, SLOT(StepSimulation())); /* Fast forward button pressed */ connect(m_pcFastForwardAction, SIGNAL(triggered(bool)), m_pcOpenGLWidget, SLOT(FastForwardPauseSimulation(bool))); /* Reset button pressed */ connect(m_pcResetAction, SIGNAL(triggered()), m_pcOpenGLWidget, SLOT(ResetSimulation())); connect(m_pcResetAction, SIGNAL(triggered()), this, SLOT(SimulationReset())); /* Capture button toggled */ connect(m_pcCaptureAction, SIGNAL(triggered(bool)), m_pcOpenGLWidget, SLOT(SetGrabFrame(bool))); /* POV-Ray XML button pressed */ connect(m_pcPOVRayXMLAction, SIGNAL(triggered()), this, SLOT(POVRaySceneXMLPopUp())); /* POV-Ray XML button pressed */ connect(m_pcPOVRayPreviewAction, SIGNAL(triggered()), this, SLOT(POVRayScenePreview())); /* 'Draw frame every' spin box value changed */ connect(m_pcDrawFrameEvery, SIGNAL(valueChanged(int)), m_pcOpenGLWidget, SLOT(SetDrawFrameEvery(int))); /* A simulation step has been completed */ connect(m_pcOpenGLWidget, SIGNAL(StepDone(int)), m_pcCurrentStepLCD, SLOT(display(int))); /* The simulation has been completed */ connect(m_pcOpenGLWidget, SIGNAL(SimulationDone()), this, SLOT(SimulationDone())); /* Toggle antialiasing */ connect(m_pcToggleAntiAliasingAction, SIGNAL(triggered(bool)), m_pcOpenGLWidget, SLOT(SetAntiAliasing(bool))); /* Quit the simulator */ connect(m_pcQuitAction, SIGNAL(triggered()), qApp, SLOT(quit())); /* Quit the simulator */ connect(m_pcAboutQTAction, SIGNAL(triggered()), qApp, SLOT(aboutQt())); /* Toggle the camera */ connect(m_pcSwitchCameraActionGroup, SIGNAL(triggered(QAction*)), this, SLOT(SwitchCamera(QAction*))); connect(this, SIGNAL(CameraSwitched(int)), m_pcOpenGLWidget, SLOT(SetCamera(int))); /* Camera focal length */ connect(m_pcFocalLength, SIGNAL(valueChanged(double)), m_pcOpenGLWidget, SLOT(SetCameraFocalLength(double))); /* POV-Ray XML button pressed */ connect(m_pcShowCameraXMLAction, SIGNAL(triggered()), this, SLOT(CameraXMLPopUp())); }
void InitSimulation() { ResetSimulation(); g_sphere.m_center = Vec3d(2.0, -1.0, 0.0); g_sphere.m_radius = 1.0; g_sphere.m_bounceFactor = 0.1; g_sphere.m_frictionFactor = 0.1; g_mesh.m_prohibitedArea = &g_sphere; }
void QVX_Sim::ResetSim() { EndRecording(); //stops any recording we may have running ResetSimulation(); ReqGLUpdate(); }
/*! The environment should have been previously initialized and linked with a single voxel object. This function sets or resets the entire simulation with the new environment. @param[in] pEnvIn A pointer to initialized CVX_Environment to import into the simulator. @param[out] RetMessage A pointer to initialized string. Output information from the Import function is appended to this string. */ bool CVX_Sim::Import(CVX_Environment* pEnvIn, CMesh* pSurfMeshIn, std::string* RetMessage) { ClearAll(); //clears out all arrays and stuff if (pEnvIn != NULL) pEnv = pEnvIn; if (pEnv == NULL) {if (RetMessage) *RetMessage += "Invalid Environment pointer"; return false;} LocalVXC = *pEnv->pObj; //make a copy of the reference digital object! if (LocalVXC.GetNumVox() == 0) {if (RetMessage) *RetMessage += "No voxels in object"; return false;} int SIndexIt = 0; //keep track of how many voxel we've added (for storing reverse lookup array...) int NumBCs = pEnv->GetNumBCs(); CVX_FRegion* pCurBc; //initialize XtoSIndexMap & StoXIndexMap XtoSIndexMap.resize(LocalVXC.GetStArraySize(), -1); // = new int[LocalVXC.GetStArraySize()]; StoXIndexMap.resize(LocalVXC.GetNumVox(), -1); // = new int [m_NumVox]; std::vector<int> Sizes(NumBCs, 0); for (int i=0; i<NumBCs; i++) Sizes[i] = pEnv->GetNumTouching(i); // pEnv->GetNumVoxTouchingForced(&Sizes); //get the number of voxels in each region (to apply equal force to each voxel within this region!) // Vec3D BCpoint; Vec3D<> BCsize = pEnv->pObj->GetLatDimEnv()/2.0; Vec3D<> WSSize = pEnv->pObj->GetWorkSpace(); //Add all Voxels: bool HasPlasticMaterial = false; Vec3D<> ThisPos; Vec3D<> ThisScale = LocalVXC.GetLatDimEnv(); //Build voxel list for (int i=0; i<LocalVXC.GetStArraySize(); i++){ //for each voxel in the array XtoSIndexMap[i] = -1; //assume there is not a voxel here... if(LocalVXC.Structure[i] != 0 ){ //if there's material here int ThisMatIndex = LocalVXC.GetLeafMatIndex(i); int ThisMatModel = LocalVXC.Palette[ThisMatIndex].GetMatModel(); if (ThisMatModel == MDL_BILINEAR || ThisMatModel == MDL_DATA) HasPlasticMaterial = true; //enable plasticity in the sim LocalVXC.GetXYZ(&ThisPos, i, false);//Get XYZ location CVXS_Voxel CurVox(this, SIndexIt, i, ThisMatIndex, ThisPos, ThisScale); XtoSIndexMap[i] = SIndexIt; //so we can find this voxel based on it's original index StoXIndexMap[SIndexIt] = i; //so we can find the original index based on its simulator position for (int j = 0; j<NumBCs; j++){ //go through each primitive defined as a constraint! pCurBc = pEnv->GetBC(j); if (pCurBc->GetRegion()->IsTouching(&ThisPos, &BCsize, &WSSize)){ //if this point is within CurVox.FixDof(pCurBc->DofFixed); CurVox.AddExternalForce(pCurBc->Force/Sizes[j]); CurVox.AddExternalTorque(pCurBc->Torque/Sizes[j]); CurVox.SetExternalDisp(pCurBc->Displace); CurVox.SetExternalTDisp(pCurBc->AngDisplace); } } if(BlendingEnabled) CurVox.CalcMyBlendMix(); //needs to be done basically last. VoxArray.push_back(CurVox); SIndexIt++; } } //add input voxel so that NumVox() works! InputVoxSInd = (int)VoxArray.size(); CVXS_Voxel TmpVox(this, 0, 0, 0, Vec3D<>(0,0,0), Vec3D<>(0,0,0)); // TmpVox.LinkToVXSim(this); VoxArray.push_back(TmpVox); //SET UP ALL PERMANENT BONDS (in between materials and the input bond) Vec3D<> RelDist; //exhaustive (slower, but still OK) for (int i=0; i<NumVox(); i++){ //for each voxel in our newly-made array for (int j = i+1; j<NumVox(); j++){ if (!LocalVXC.IsAdjacent(StoXIndexMap[i], StoXIndexMap[j], false, &RelDist)) continue; if (!CreateBond(B_LINEAR, i, j, true) && RetMessage) *RetMessage += "At least one bond creation failed during import"; } } //Create input bond CreateBond(B_INPUT_LINEAR_NOROT, InputVoxSInd, InputVoxSInd, true, &InputBondInd, false); //create input bond, but initialize it to meaningless connection to self UpdateAllBondPointers(); //necessary since we probably reallocated the bond array when adding pbonds the first time //Set up our surface list... for (int i=0; i<NumVox(); i++){ //for each voxel in our newly-made array if (VoxArray[i].GetNumLocalBonds() != 6){ SurfVoxels.push_back(i); } //todo: only do for those on surfaces, I think. VoxArray[i].CalcNearby((int)(CollisionHorizon*1.5)); //populate the nearby array } #ifdef USE_OPEN_GL VoxMesh.ImportLinkSim(this); VoxMesh.DefMesh.DrawSmooth = false; //if the input mesh is not valid, use marching cubes to create one if (!pSurfMeshIn){ CMesh GeneratedSmoothMesh; CArray3Df OccupancyArray(pEnv->pObj->GetVXDim(), pEnv->pObj->GetVYDim(), pEnv->pObj->GetVZDim()); int NumPossibleVox = pEnv->pObj->GetStArraySize(); for (int g=0; g<NumPossibleVox; g++){ if (pEnv->pObj->Structure.GetData(g)>0) OccupancyArray[g] = 1.0; } CMarchCube::SingleMaterial(&GeneratedSmoothMesh, &OccupancyArray, 0.5, pEnv->pObj->GetLatticeDim()); SurfMesh.ImportSimWithMesh(this, &GeneratedSmoothMesh); } else SurfMesh.ImportSimWithMesh(this, pSurfMeshIn); #endif ResetSimulation(); OptimalDt = CalcMaxDt(); //to set up dialogs parameter ranges, we need this before the first iteration. EnablePlasticity(HasPlasticMaterial); //turn off plasticity if we don't need it... Initalized = true; // std::string tmpString; std::ostringstream os; os << "Completed Simulation Import: " << NumVox() << " Voxels, " << NumBond() << "Bonds.\n"; *RetMessage += os.str(); return true; }