Jump to content

[SOLVED] Get to normal at ObjectWater


photo

Recommended Posts

vec3 ObjectWater::getNormal(const Vec3 &position) const {
vec3 normal = vec3_zero;
float time = engine.game->getTime();
vec3 iposition = vec3(getIWorldTransform() * position);
for(int i = 0; i < 4; i++) {
	float distance = waves[i].x * iposition.x - waves[i].y * iposition.y;
	float cos_phase = Math::cos((distance + time) * waves[i].z);
	normal.x -= cos_phase * waves[i].x * waves[i].z * waves[i].w;
	normal.y += cos_phase * waves[i].y * waves[i].z * waves[i].w;
}
normal.z = 1.0f;
return mul3(normal,getWorldTransform(),normalize(normal));
}

Link to comment
×
×
  • Create New...