Skip to content

Instantly share code, notes, and snippets.

@yorung
Created December 3, 2017 05:40
Show Gist options
  • Save yorung/0a2eed2ccd6e7583a54fe6713eec3103 to your computer and use it in GitHub Desktop.
Save yorung/0a2eed2ccd6e7583a54fe6713eec3103 to your computer and use it in GitHub Desktop.
Tilt cubes along the waves.
Vec3 center = pos + CalcGerstnerWaveOffset(immutableCb, pos, terrainFrameCB.g_time);
Vec3 offsetXZ = pos + Vec3(1, 0, 1) + CalcGerstnerWaveOffset(immutableCb, pos + Vec3(1, 0, 1), terrainFrameCB.g_time);
Vec3 offsetNegX = pos + Vec3(-1, 0, 0) + CalcGerstnerWaveOffset(immutableCb, pos + Vec3(-1, 0, 0), terrainFrameCB.g_time);
Vec3 offsetNegZ = pos + Vec3(0, 0, -1) + CalcGerstnerWaveOffset(immutableCb, pos + Vec3(0, 0, -1), terrainFrameCB.g_time);
Vec3 normal = normalize(cross(offsetNegZ - offsetXZ, offsetNegX - offsetXZ));
Vec3 rotAxis = normalize(cross(normal, Vec3(0, 1, 0)));
float rotRad = acos(dot(normal, Vec3(0, 1, 0)));
cube.Draw(MeshXAnimResult(), scale(5, 5, 5) * q2m(Quat(rotAxis, -rotRad)) * translate(center.x, center.y, center.z));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment