# Rotating sine waves in 3D space

Hey!

I’m trying to modulate a mesh 3D grid with a sine wave in a rotated direction. That is, I want the sine wave to be rotated relative to the mesh, such that it is affecting the mesh on an angle.… This was my attempt, however it does not seem to do anything. Moving the rotate around the mesh.draw, just rotates everything - not the sinewave in relation to the mesh.

``````ofPushMatrix();
ofRotateZ(40);
ofRotateX(40);
float time = ofGetElapsedTimef();
for (int y=0; y<H; y++) {
for (int x=0; x<W; x++) {
int i = x + W * y;
ofPoint p = mesh.getVertex( i );
float amp = x/40.0 + time;
float zScale = 10*sin(amp);
p.z = zScale;
mesh.setVertex( i, p );
}
}
ofPopMatrix();
``````

Thanks

Figured this out thanks to the help of Pete Werner on the forums. The solution is to rotate the x that is feed into sin.

``````float time = (ofGetFrameNum() % 360) / 360.0;
float amp = 50;
for (int x = 0; x < numVertsX; x++) {
for (int y = 0; y < numVertsY; y++) {
int i = x + numVertsY * y;
ofPoint p = m.getVertex(i);
ofPoint p2 = p;
float tmpX = p.x * cos(rot) - p.y * sin(rot);
float theta = (tmpX/(float)plane.getWidth() + time) * TWO_PI;
float zScale = amp * sin(theta);
p2.z = zScale;