How Do You Update Position, Transform Points, and Render Shapes in Programming?

  • Thread starter Thread starter seacreature
  • Start date Start date
  • Tags Tags
    Coding Function
AI Thread Summary
The discussion focuses on programming functions for updating positions, transforming points, and rendering shapes. A user seeks guidance on implementing these functions without needing specific code, emphasizing the desire for formulas or resources. Key points include the need for understanding 2D kinematics and rotation matrices for accurate position updates and transformations. The user has attempted to implement movement using trigonometric functions but encounters issues with the y-direction movement. Overall, the conversation highlights the importance of foundational concepts in linear transformations and kinematics for successful coding in graphics programming.
seacreature
Messages
3
Reaction score
0
help needed please.. don't need the code. but i need formula or any source that can help me. i want to try code it myself. =)

can anyone help me with this function:


// Function to be used to update the position. Given the current position,
// the direction in which the tank is looking, and the speed it is moving,
// modify position to the new position
function UpdatePosition_Axis(ref position, direction, speed)
{
*what is this asking for?*
}

// Function used to transform a point by an angle and scale, and translated by a position.
// Follows Linear Transformations: x' = p + A * x
function TransformPoint(model, position, direction, scale)
{
*and this*
}

// Function used to render a generic rectangle. It uses the position, angle, and scale to transform
// each point of the normalized rectangle model, and display the rectangle on the screen
function RenderRectangle(position, direction, scale, c)
{
*sorry, plus this*
}

Given: for part b
// Normalized Model of a rectangle.
point2d model_top_left = [-0.5, 0.5];
point2d model_top_right = [ 0.5, 0.5];
point2d model_bottom_right = [ 0.5, -0.5];
point2d model_bottom_left = [-0.5, -0.5];


help is much appreciated. thanks
 
Last edited:
Physics news on Phys.org
What have you tried? What language is this?

In the first function, you are going to have something like:

tank.ref_pos = ref_pos;
tank.speed =speed;
tank.direction = direction;
 
yeah.. i had tried it.. is in HLPL

my function

pos.x = pos.x * cos(direction) + speed;
pos.y = pos.y * sin(direction) + speed;

but the problem is, the object able to move in x direction but when moving in y direction, the object so off elsewhere.
 
seacreature said:
yeah.. i had tried it.. is in HLPL

my function

pos.x = pos.x * cos(direction) + speed;
pos.y = pos.y * sin(direction) + speed;

but the problem is, the object able to move in x direction but when moving in y direction, the object so off elsewhere.

Sorry; I don't know HLPL
 
Robert1986 said:
Sorry; I don't know HLPL

thanks for the offer of helping though. =)
 
I just skimmed through the instructions, but to me it seems like you need to do the following:

1. 2d kinematics, namely \mathbf{r}(t) = \mathbf{r}_0 + \dot{\mathbf{r}}t
2. Rotation matrix to transfer angle and then add pose vector. (Look at the Wikipedia article on rotation matrices)
3. Use the given nonrotated rectangle of sides 1 unit and then use linear transformations to scale, rotate, and translate it.
 
Back
Top