Moving objects using an array of data

Get answers to all your basic programming questions. No Ogre questions, please!
gabriel
Gnoblar
Posts: 6
Joined: Tue Feb 07, 2012 8:21 pm

Moving objects using an array of data

Post by gabriel »

Hey guys,

I hope somebody can help me with this issue:

What my main goal is:
Given a certain array of numbers (say between xmin = 0 and xmax = 100): eg: x = [0, 5, 27, 15, 55, 89, 34, 100, 9, 73].
I have created a block located at node (0,0,0).
I want to create a loop that would continuously read the incoming numbers in the array in order then translate the block on the x-axis (in the right direction) according to each received value.
In other words: Say the block is first at 0,0,0 then the loop would first read the "0" which corresponds to no translation. The second number in line is "5" so the block is translated 5 unit to the right (it is now at 5,0,0), so on and so forth...

Also, how could I arbitrary set the time between each read( i.e Say I want to the block to do a translation operation every 0.75 seconds)

What I have so far:
Using the tutorial and base application provided in the tutorial section, I have added in an extra piece of code which does the following:
I have a block located at 0,0,0 every time I press the letter "K" on my keyboard the block translate 10 units to the right,
and every time I press "J" the block translate 10 units to the left (on the x-axis).

I know... its not quite what I wanted to do, but its a start

If anybody could tell what methods should I use and how should I approach this problem I would be very grateful thanks
PS: (Im not a C++ guy, I just started to learn the language)
User avatar
madmarx
OGRE Expert User
OGRE Expert User
Posts: 1671
Joined: Mon Jan 21, 2008 10:26 pm
x 50

Re: Moving objects using an array of data

Post by madmarx »

Hi.
It's not really a General Discussion, more a "back to basics" one.

The question is :
where are the "incoming numbers" coming from?
Do you have just an array to read (and cycle back to the beginning) ? In that case, create your array (either with a C array or a std::vector), fill it and then, just store an "int" which will be the current index inside the array. Then each frame : currentIndex = (currentIndex+1) % arraySize; (knowing that '%' is the mathematical modulo), and then you just need to translate from yourArray[currentIndex];

Best regards,

Pierre
Tutorials + Ogre searchable API + more for Ogre1.7 : http://sourceforge.net/projects/so3dtools/
Corresponding thread : http://www.ogre3d.org/forums/viewtopic. ... 93&start=0
gabriel
Gnoblar
Posts: 6
Joined: Tue Feb 07, 2012 8:21 pm

Re: Moving objects using an array of data

Post by gabriel »

Thanks for the reply, I'll look into it....

In this context, I'm a using a "test array" (i.e. I will just declare array "x" with arbitrary values)
(Eventually I would like to incorporate rotation as well as translation)
gabriel
Gnoblar
Posts: 6
Joined: Tue Feb 07, 2012 8:21 pm

Re: Moving objects using an array of data

Post by gabriel »

...and yes, for this case the loop would cycle back to the first value once the final value is read