hessiess
(hessiess)
October 6, 2008, 4:07am
1
Mostly out of a lack of inspiration I decided to Wright a pong clone, the result of which can be found here (Linux bin in root, source code is included for users of other platforms)
the main reason im positing here is I’ve run into a problem with making the ball roll in the direction its moving. currently all I’ve managed to achieve is the ball wobbling around randomly. douse anyone here know how to make the ball roll correctly?
thanks in advance.
Wereaser
(Wereaser)
October 6, 2008, 4:12am
2
Could it be possible that you’re doing the rotation in local coordinates instead in world coordinates?
hessiess
(hessiess)
October 6, 2008, 4:39am
3
Im using
node -> setRotation(vector3df)
which is global as far as im aware, though please correct me if im wrong (node->setPosition() is unafected by setRotation)
hares the code that calculating the rotations, basicly it divides up the circumference into angle steps, and works out how meany steps to rotate the ball on the x and z acsisses.
void movable_ball::move_ball(core::vector3df loc)
{
if(switchh == 0)
switchh = 1;
else
switchh = 0;
// set position
ball->setPosition(loc);
// calculate movement delta
core::vector3df mov_delta = loc - old_loc;
// calculate rotation for X accsis
if(switchh == 1)
{
for(int angle = -30; angle < 31; angle ++)
{
float dist_moved_min = angle_step * angle;
float dist_moved_max = angle_step * (angle +1);
if(mov_delta.X > dist_moved_min && mov_delta.X < dist_moved_max)
{
// fix speed bug when angle is negative
if(mov_delta.X < 0)
angle += 1;
// apply rotation
core::vector3df ball_rot = ball->getRotation();
ball->setRotation(core::vector3df(ball_rot.X,ball_rot.Y,ball_rot.Z -= angle));
break;
}
}
} // end X acsiss rotation
else
{
// calculate rotation for Y accsis
for(int angle = -30; angle < 31; angle ++)
{
float dist_moved_min = angle_step * angle;
float dist_moved_max = angle_step * (angle +1);
if(mov_delta.Z > dist_moved_min && mov_delta.Z < dist_moved_max)
{
// fix speed bug when angle is negative
if(mov_delta.Z < 0)
angle += 1;
// apply rotation
core::vector3df ball_rot = ball->getRotation();
ball->setRotation(core::vector3df(ball_rot.X += angle,ball_rot.Y,ball_rot.Z));
break;
}
}
// save old location
old_loc = loc;
}
}
Nickster
(Nickster)
October 6, 2008, 7:33am
4
Man, this off-topic thread has turned into a scripting thread!
But I like it
Sorry I can’t help with your problem though…
arexma
(arexma)
October 6, 2008, 1:31pm
5
Just to sort out some terminology:
C and its childs (c++, c#) are not scripting languages… It is an imperative/object oriented compiled/interpreted language
lisp, html, php and so on would be scripting languages.
Nickster
(Nickster)
October 6, 2008, 2:13pm
6
arexma:
Just to sort out some terminology:
C and its childs (c++, c#) are not scripting languages… It is an imperative/object oriented compiled/interpreted language
lisp, html, php and so on would be scripting languages.
Ah, okay, It was just a ‘figure of speech’.
Now don’t go ranting about ‘figures of speech’!!
hessiess
(hessiess)
October 6, 2008, 10:51pm
7
arexma:
Just to sort out some terminology:
C and its childs (c++, c#) are not scripting languages… It is an imperative/object oriented compiled/interpreted language
lisp, html, php and so on would be scripting languages.
technically speaking HTML is a markup language (hyper text markup language), JavaScript however is a scripting language;)
however, this thread was originally about fixing the problem with my ball rolling algorithm, can we get back on topic?
IanC
(IanC)
October 7, 2008, 1:44am
8
Can’t get the game to do anything weird (doesn’t respond to my input, and the ball moves fine in the first bit of its trip), so this is a bit of a guess.
Are you using a game engine for this? If so, maybe it’s got a physics engine? This would make the rotations you apply add forces to the ball, moving it around.
hessiess
(hessiess)
October 7, 2008, 2:01am
9
IanC:
Can’t get the game to do anything weird (doesn’t respond to my input, and the ball moves fine in the first bit of its trip), so this is a bit of a guess.
Are you using a game engine for this? If so, maybe it’s got a physics engine? This would make the rotations you apply add forces to the ball, moving it around.
j = down, k = up (like vim )
the ball moves fine, but doesn’t roll in the direction its moving, sometimes it actually rolls backwards.