#### Archived

This topic is now archived and is closed to further replies.

# Moving images in a 2d enviroment

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

## Recommended Posts

I have a class that controls the images that are on the screen. It controls the images moving, so I use newton´s formula S=Sº+Vº*t+1/2*at² S in pixels and t in miliseconds I use a timer with a refresh rate to redraw the image every n miliseconds.. so the user of this class if wants to move an image pass the initial speed and the accelaration for each of the axis x and y the problem is when to stop moving I thought that maybe the user could set the final position but what to do if when I am recalculating the image position (based on speed, acceleration and time passed) the image passes the final position eg: x==40 , finalXpos==50 but I am icr x in 25 I guess I could just set x to finalXpos but if y needs another 1000 time units to get to its final position?the image just doent´s move on the x axis for the next 1000 time units? any help is apreciated... []´s Marcel

##### Share on other sites
From what I gather (though I''m not exactly clear of your issue)... I think you just need to store the image location in non integer coordinates.. and convert them to integers for display. This avoids having to make all these clever algorithms you are thinking about.

##### Share on other sites
I don''t see how using float will change anything at all..
but anyway that''s not something possible with the environment I''m working with

##### Share on other sites
If you need it to move following that formula.. and hte user to be able to specify a final location.. then (for fixed acceleration) you just need to solve the 2 equations (for x and y motion) and obtain an initial velocity in each direction to reach the required destination. The object can then be projected at an appropriate velocity. This is (eg) how you might make a cannon ball (which follows an approximately parabolic path) fire, and hit a required target. Obviously.. there are 2 solutions to the equation... and You''ll just have to pick the appropriate one (perhaps the one with the lowest initial velocity... or something more refined). You also obtain the value of time at which it''ll reach it''s target. You then run the sim, with the initial velocities you''ve just found... until time reaches the point you solved for... then set the final location. I guess you''d do this at time intervals determined by the time per frame to give consistant movement. Since you are using this formula of newtons (rather than integrating f=ma, as force is constant)... you can get the exact location of the object at any point in the future, so you can almost guarantee that it''ll reach it''s destination. In any case... tracking it''s location should be done with non integer coordinates as I suggested.. so you should really use fixed point (shouldn''t be a problem). This is important because of the varying timestep length (unless you choose ms as you base time units.. instead of secs). I find it a lot easier to work with standard and uniform units at all times... ie metres, and seconds.

##### Share on other sites
I don't really need to move following this formula, if you suggest something better...
actually I don't have a fixed acceleration
I uses f=kx, with objects mass always ==1 to sim spring move
I adopt fixed acceleration between each refresh
the cannon ball move is a good exemple of what I want to do, and that's leads to other problem, I would have to adjust something, my question is what?I thought in adjusting the k value..

I think is a good ideia the user sets the time value the objects has to reach its destination..so I may calculate the k value

quote:

.. there are 2 solutions to the equation...

what 2 solutions?

and I really can't use floating point, that's not supported by the processor so all floating point operations are emulated, decreasing the performace

[edited by - marcels on February 24, 2004 10:53:33 PM]

##### Share on other sites
Fixed point mathematics lets you use non integer coordinates/values using only integer values, and is in general not very costly. Given the time constraint specified by the user.. there is only one solution.. sorry, I was thinking of something else. For a fixed initial velocity, there are only 2 solutions... if any velocity is allowable, then there are an infinite number... hence the additional time constraint to get an explicit solution.

1. 1
Rutin
45
2. 2
3. 3
4. 4
5. 5
JoeJ
19

• 11
• 13
• 10
• 12
• 10
• ### Forum Statistics

• Total Topics
633001
• Total Posts
3009821
• ### Who's Online (See full list)

There are no registered users currently online

×