# 3D Movement in Cubic Grids

This topic is 2948 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi,
I would like to do a simple movement effect for a grid of cubes. I would like to move a cube in a grid a specified distance, then after few seconds, it should go back to its initial position. I've written few codes, but the cube can go only forward but can't move back.
 void ocvCaptureApp::update() { if( mCap &amp;&amp; mCap.checkNewFrame() ) { ci::Surface surface(mCap.getSurface()); cv::Mat input( toOcv( surface ) ); cv::Mat sobel; cv::Sobel(input, sobel, CV_32F, 1, 1); if(numBlocks==0) return; int h = input.rows / temp; int w = input.cols / temp; float pos; for (int r = 0; r<temp; r++)="" {="" for(int="" c="0;" c<temp;="" c++)="" cv::scalar="" weight="cv::sum(sobel(cv::Range(h*r," (r+1)*h),="" cv::range(c*w,="" (c+1)*w)));="" if="" (weight[0]="" +="" weight[1]=""> colorThershold) // if motion is detected { input(cv::Range(h*r, (r+1)*h-1), cv::Range(c*w, (c+1)*w-1)).setTo(cv::Scalar(0,0,255)); // put a red color in the cube pos = cubes[r][c].Get_Position().y; // get its position pos-=x; cubes[r][c]._pos.y=pos; if(cubes[r][c]._pos.y&lt;-40.0f ) // if its lower than -40 { cubes[r][c]._pos.y=-40.0f; savedY = cubes[r][c]._pos.y; mTimer.start(); bEffect=true; } } if(mTimer.isOver(delayThershold) &amp;&amp; bEffect==true) { pos = cubes[r][c].Get_Position().y; pos+=x; cubes[r][c]._pos.y=pos; if(cubes[r][c]._pos.y&gt;=savedY) { cubes[r][c]._pos.y=savedY; mTimer.stop(); mTimer.reset(); bEffect=false; } } } } mTexture = gl::Texture(fromOcv(input)); } } 

</temp;>

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 16
• 11
• 23
• 42
• 75