# Homework Help: Function / coding

1. Jul 26, 2012

### seacreature

help needed please.. dont 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)
{
}

// 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: Jul 26, 2012
2. Jul 26, 2012

### Robert1986

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;

3. Jul 26, 2012

### seacreature

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.

4. Jul 26, 2012

### Robert1986

Sorry; I don't know HLPL

5. Jul 26, 2012

### seacreature

thanks for the offer of helping though. =)

6. Jul 27, 2012

### jhae2.718

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.