graphics - Align shape to vector using Dgame framework and D language -


i've been using dgame framework simple simulations.

i need moving object aligned velocity vectors.

how possible using dgame?

i see shape object has setrotation , setrotationcenter. not sure how use these achieve effect. realize default rotation around origin. causes objects drift on time.

sample code

struct gameobject { point **position; // array of pointers object points point *acceleration; point *velocity; double max_speed; double max_force; }  shape = new shape(geometry.quads, vertex(object.position[0].x, object.position[0].y), vertex(object.position[1].x, object.position[1].y), vertex(object.position[2].x, object.position[2].y), vertex(object.position[3].x, object.position[3].y))  // rotate shape face velocity here shape.move(object.velocity.x, object.velocity.y); 

you can achieve using atan2. depending on orientation of texture might need change values bit or add 90/-90 degrees.

for textures face up:

rotation = atan2(-velocity.x, velocity.y); 

for textures face right:

rotation = atan2(-velocity.y, -velocity.x); 

you might need convert result radians degrees or other way around.


Comments

Popular posts from this blog

searchKeyword not working in AngularJS filter -

sequelize.js - Sequelize: sort by enum cases -

user interface - how to replace an ongoing process of image capture from another process call over the same ImageLabel in python's GUI TKinter -