Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualKaptein

Posted 26 December 2012 - 07:13 PM

i probably wouldn't go that far with plants, unless they are complex plants
it's more likely just a classic case of stretching, scaling and skewering
you can do all of this with matrix ops, or simply moving the vertices of a quad
note that this will distort the texture!

i imagine that in trine, it's alot more involved than that
some game companies animate plant movement for common plants, since that always gives the best result
however, it should be enough to just modulate the plant vertex positions a little

a basic formula would be:
const float MAX = ...
const float POWER = ...

x = 1.0 - min(MAX, distance(player, plant)) / MAX // get euclidian distance
z = (plant.x - player.x) / MAX // get signed X-distance
vertex.top_left += x * z * POWER
vertex.top_right += x * z * POWER

in a shader, you can easily find the top vertices in one go by multiplying with .t, assuming t == 1 at the top of the texture
like this:
vertex.x += x * z * POWER * texCoord.t;

note that 1D distance is a simple calculation: abs(x1 - x2)
but for it to be signed, lose the abs() and you can tell which side the player is on!

#2Kaptein

Posted 26 December 2012 - 07:10 PM

i probably wouldn't go that far with plants, unless they are complex plants
it's more likely just a classic case of stretching, scaling and skewering
you can do all of this with matrix ops, or simply moving the vertices of a quad
note that this will distort the texture!

i imagine that in trine, it's alot more involved than that
some game companies animate plant movement for common plants, since that always gives the best result
however, it should be enough to just modulate the plant vertex positions a little

a basic formula would be:
const float MAX = ...
const float POWER = ...

x = 1.0 - min(MAX, distance(player, plant)) / MAX // get euclidian distance
z = distance(player.x, plant.x) / MAX // get signed X-distance
vertex.top_left += x * z * POWER
vertex.top_right += x * z * POWER

in a shader, you can easily find the top vertices in one go by multiplying with .t, assuming t == 1 at the top of the texture
like this:
vertex.x += x * z * POWER * texCoord.t;

#1Kaptein

Posted 26 December 2012 - 07:09 PM

i probably wouldn't go that far with plants, unless they are complex plants<br />it's more likely just a classic case of stretching, scaling and skewering<br />you can do all of this with matrix ops, or simply moving the vertices of a quad<br />note that this will distort the texture!<br /><br />i imagine that in trine, it's alot more involved than that<br />some game companies animate plant movement for common plants, since that always gives the best result<br />however, it should be enough to just modulate the plant vertex positions a little<br /><br />a basic formula would be:<br />const float MAX = ...<br />const float POWER = ...<br /><br />x = 1.0 - min(MAX, distance(player, plant)) / MAX // get euclidian distance<br />z = distance(player.x, plant.x) / MAX // get signed X-distance<br />vertex.top_left += x * z * POWER<br />vertex.top_right += x * z * POWER<br /><br />in a shader, you can easily find the top vertices in one go by multiplying with .t, assuming t == 1 at the top of the texture<br />like this:<br />vertex.x += x * z * POWER * texCoord.t;<br />

PARTNERS