yade-dev team mailing list archive
-
yade-dev team
-
Mailing list archive
-
Message #07512
[Branch ~yade-dev/yade/trunk] Rev 2829: - Fix the behavior of bodies moved with the mouse with respect to the new isDynamic behaviour.
------------------------------------------------------------
revno: 2829
committer: Bruno Chareyre <bruno.chareyre@xxxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2011-04-22 11:01:59 +0200
message:
- Fix the behavior of bodies moved with the mouse with respect to the new isDynamic behaviour.
- The velocity is now defined correctly so that contacts on the moved object are computed correctly
modified:
gui/qt4/GLViewer.cpp
pkg/dem/NewtonIntegrator.cpp
pkg/dem/NewtonIntegrator.hpp
--
lp:yade
https://code.launchpad.net/~yade-dev/yade/trunk
Your team Yade developers is subscribed to branch lp:yade.
To unsubscribe from this branch go to https://code.launchpad.net/~yade-dev/yade/trunk/+edit-subscription
=== modified file 'gui/qt4/GLViewer.cpp'
--- gui/qt4/GLViewer.cpp 2011-02-27 13:54:43 +0000
+++ gui/qt4/GLViewer.cpp 2011-04-22 09:01:59 +0000
@@ -40,7 +40,8 @@
/*****************************************************************************
*********************************** SnapshotEngine ***************************
*****************************************************************************/
-
+static int last(-1);
+static unsigned initBlocked(State::DOF_NONE);
CREATE_LOGGER(SnapshotEngine);
void SnapshotEngine::action(){
if(!OpenGLManager::self) throw logic_error("No OpenGLManager instance?!");
@@ -311,7 +312,7 @@
else if(e->key()==Qt::Key_D) {timeDispMask+=1; if(timeDispMask>(TIME_REAL|TIME_VIRT|TIME_ITER))timeDispMask=0; }
else if(e->key()==Qt::Key_G) { if(e->modifiers() & Qt::ShiftModifier){ drawGrid=0; return; } else drawGrid++; if(drawGrid>=8) drawGrid=0; }
else if (e->key()==Qt::Key_M && selectedName() >= 0){
- if(!(isMoving=!isMoving)){displayMessage("Moving done."); mouseMovesCamera();}
+ if(!(isMoving=!isMoving)){displayMessage("Moving done."); if (last>=0) {Body::byId(Body::id_t(last))->state->blockedDOFs=initBlocked; last=-1; Omega::instance().getScene()->selectedBody = -1;} mouseMovesCamera();}
else{ displayMessage("Moving selected object"); mouseMovesManipulatedFrame();}
}
else if (e->key() == Qt::Key_T) camera()->setType(camera()->type()==qglviewer::Camera::ORTHOGRAPHIC ? qglviewer::Camera::PERSPECTIVE : qglviewer::Camera::ORTHOGRAPHIC);
@@ -485,14 +486,31 @@
qglviewer::Vec vd=camera()->viewDirection(); renderer->viewDirection=Vector3r(vd[0],vd[1],vd[2]);
if(Omega::instance().getScene()){
+ const shared_ptr<Scene>& scene=Omega::instance().getScene();
int selection = selectedName();
if(selection!=-1 && (*(Omega::instance().getScene()->bodies)).exists(selection) && isMoving){
- static int last(-1);
+ static Real lastTimeMoved(0);
+ static Real initv0(0); static Real initv1(0); static Real initv2(0);
+ float v0,v1,v2; manipulatedFrame()->getPosition(v0,v1,v2);
if(last == selection) // delay by one redraw, so the body will not jump into 0,0,0 coords
{
Quaternionr& q = (*(Omega::instance().getScene()->bodies))[selection]->state->ori;
Vector3r& v = (*(Omega::instance().getScene()->bodies))[selection]->state->pos;
- float v0,v1,v2; manipulatedFrame()->getPosition(v0,v1,v2);v[0]=v0;v[1]=v1;v[2]=v2;
+ Vector3r& vel = (*(Omega::instance().getScene()->bodies))[selection]->state->vel;
+ Vector3r& angVel = (*(Omega::instance().getScene()->bodies))[selection]->state->angVel;
+ angVel=Vector3r::Zero();
+ if (!initv0 && !initv1 && !initv2){initv0=v0;initv1=v1;initv2=v2;}
+ if (initv0!=v0 || initv1!=v1 || initv2!=v2) {
+ Real dt=(scene->time-lastTimeMoved); lastTimeMoved=scene->time;
+ if (dt!=0) {
+ vel[0]=-(v[0]-v0)/dt; vel[1]=-(v[1]-v1)/dt; vel[2]=-(v[2]-v2)/dt;
+ vel[0]=-(initv0-v0)/dt; vel[1]=-(initv1-v1)/dt; vel[2]=-(initv2-v2)/dt;
+ initv0=v0;initv1=v1;initv2=v2;
+ }
+ }
+ else {vel[0]=vel[1]=vel[2]=0; /*v[0]=v0;v[1]=v1;v[2]=v2;*/}
+ v[0]=v0;v[1]=v1;v[2]=v2;
+ //FIXME: should update spin like velocity above, when the body is rotated:
double q0,q1,q2,q3; manipulatedFrame()->getOrientation(q0,q1,q2,q3); q.x()=q0;q.y()=q1;q.z()=q2;q.w()=q3;
}
(*(Omega::instance().getScene()->bodies))[selection]->userForcedDisplacementRedrawHook();
@@ -515,7 +533,6 @@
}
renderer->clipPlaneSe3[manipulatedClipPlane]=newSe3;
}
- const shared_ptr<Scene>& scene=Omega::instance().getScene();
scene->renderer=renderer;
renderer->render(scene, selectedName());
}
@@ -536,6 +553,8 @@
LOG_DEBUG("Selection is "<<selectedName());
int selection = selectedName();
if(selection<0){
+ if (last>=0) {
+ Body::byId(Body::id_t(last))->state->blockedDOFs=initBlocked; last=-1; Omega::instance().getScene()->selectedBody = -1;}
if(isMoving){
displayMessage("Moving finished"); mouseMovesCamera(); isMoving=false;
Omega::instance().getScene()->selectedBody = -1;
@@ -546,8 +565,11 @@
resetManipulation();
if(Body::byId(Body::id_t(selection))->isClumpMember()){ // select clump (invisible) instead of its member
LOG_DEBUG("Clump member #"<<selection<<" selected, selecting clump instead.");
- selection=Body::byId(Body::id_t(selection))->clumpId;
+ selection=Body::byId(Body::id_t(selection))->clumpId;
}
+ initBlocked=Body::byId(Body::id_t(selection))->state->blockedDOFs;
+ Body::byId(Body::id_t(selection))->state->blockedDOFs=State::DOF_ALL;
+
setSelectedName(selection);
LOG_DEBUG("New selection "<<selection);
displayMessage("Selected body #"+lexical_cast<string>(selection)+(Body::byId(selection)->isClump()?" (clump)":""));
=== modified file 'pkg/dem/NewtonIntegrator.cpp'
--- pkg/dem/NewtonIntegrator.cpp 2011-04-03 16:49:58 +0000
+++ pkg/dem/NewtonIntegrator.cpp 2011-04-22 09:01:59 +0000
@@ -70,6 +70,7 @@
void NewtonIntegrator::action()
{
scene->forces.sync();
+ bodySelected=(scene->selectedBody>=0);
if(warnNoForceReset && scene->forces.lastReset<scene->iter) LOG_WARN("O.forces last reset in step "<<scene->forces.lastReset<<", while the current step is "<<scene->iter<<". Did you forget to include ForceResetter in O.engines?");
const Real& dt=scene->dt;
homoDeform=(scene->isPeriodic ? scene->cell->homoDeform : -1); // -1 for aperiodic simulations
@@ -166,7 +167,7 @@
saveMaximaVelocity(id,state);
// move individual members of the clump, save maxima velocity (for collider stride)
if(b->isClump()) Clump::moveMembers(b,scene,this);
-
+
#ifdef YADE_BODY_CALLBACK
// process callbacks
for(size_t i=0; i<callbacksSize; i++){
@@ -197,7 +198,7 @@
} else if (homoDeform==Cell::HOMO_POS){
state->pos+=scene->cell->velGrad*state->pos*dt;
}
- state->pos+=state->vel*dt;
+ if (!bodySelected || scene->selectedBody!=id) state->pos+=state->vel*dt;
}
void NewtonIntegrator::leapfrogSphericalRotate(State* state, const Body::id_t& id, const Real& dt )
=== modified file 'pkg/dem/NewtonIntegrator.hpp'
--- pkg/dem/NewtonIntegrator.hpp 2011-01-09 16:34:50 +0000
+++ pkg/dem/NewtonIntegrator.hpp 2011-04-22 09:01:59 +0000
@@ -38,6 +38,8 @@
// whether the cell has changed from the previous step
bool cellChanged;
+ // wether a body has been selected in Qt view
+ bool bodySelected;
int homoDeform; // updated from scene at every call; -1 for aperiodic simulations, otherwise equal to scene->cell->homoDeform
Matrix3r dVelGrad; // dtto