Jump to content
  • Advertisement
Sign in to follow this  
AhmedSaleh

3D Movement in Cubic Grids

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

If you intended to correct an error in the post then please contact us.

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 && 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;>

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!