void Cylinder::collide(Particle &particle)const { YsVec3 r=particle.getPosition(); YsVec3 v=particle.getVelocity(); YsVec3 n; //particle penetrates neither bottom nor radius if (bottom_fun(r)<0 && side_fun(r)<0) { return; } if (bottom_fun(r)>0) { n=YsYVec(); if (n*v<0) { v=v-2*(v*n)*n; //bounce velocity particle.setVelocity(v); } } if (side_fun(r)>0) { n=origin-r; n.SetY(0.0); n.Normalize(); if (n*v<0) { v=v-2*(v*n)*n; //bounce velocity particle.setVelocity(v); } } }
void YsInverseViewportTransformation(YsVec3 &vOut,const YsVec3 &vIn,const int viewport[4]) { vOut.SetX((vIn.x()-(double)viewport[0])*2.0/(double)viewport[2]-1.0); vOut.SetY((vIn.y()-(double)viewport[1])*2.0/(double)viewport[3]-1.0); }
void YsViewportTransformation(YsVec3 &vOut,const YsVec3 &vIn,const int viewport[4]) { vOut.SetX((double)viewport[0]+(double)viewport[2]*(vIn.x()+1.0)/2.0); vOut.SetY((double)viewport[1]+(double)viewport[3]*(vIn.y()+1.0)/2.0); }