- Home /
- Shader Hacking /

In OSL we have a rotate function,

"point rotate (point Q, float angle, point P0, point P1) Returns the point computed by rotating point Q by angle radians about the axis that passes from point P0 to P1."

but I cannot find an equivalent function in ai_vector.h that would enable me to rotate a AtVector.

I looked at ai_matrix.h in the hope of finding a function or functions that I might use but without any luck. Do you have any suggestions?

Comment

**Answer** by Malcolm Kesson
·
Sep 03 at 07:36 PM

Mads.

This seems to be working OK.

http://fundza.com/arnold_shaders/polygon/polygon.cpp.html

Malcolm

**Answer** by Mads DrÃ¸schler
·
Sep 03 at 03:31 PM

Don't know if I understand correctly, but we dont need rotate() in OSL to rotate, we can build by generic items, maybe you can do the same.

You setup the matrix rotation function with cos and sin.

Then call it, and multiply with the UV.

In OSL we cant do that directly,

so we would have to actually update the uv print

uv = transform(rotate2d(Time),uv);

matrix rotate2d( float angle ) { return matrix(cos(angle),-sin(angle),0,0,sin(angle),cos(angle),0,0,0,0,0,0,0,0,0,0); shader ( float angle = 0, // increment over time point Po = P, // Incoming UVW ) { point uv = Po; // then down in body or somewhere else call this // You want to multiply the incoming uv with the matrix. // Generic: uv = rotate2d(angle) * uv; // OSL uv = transform(rotate2d(angle),uv) }

**Answer** by Malcolm Kesson
·
Sep 03 at 04:40 PM

Sorry Mads but I did not make it clear that I am using C++ not OSL. I am converting an OSL shader to its C++ plugin equivalent. The shader I am converting is here,

http://fundza.com/rfm/osl/regular_polygon/index.html#code

I thought the following would work but it gives the wrong results.

// 4 Apply the rotation to a 3D point defined by the uv location.

AtVector uvPnt = AtVector(sg->u - 0.5, 0.5 - sg->v, 0);

AtMatrix mat_rot = AiM4RotationZ(rotation);

AtVector rotPnt = AiM4VectorByMatrixMult(mat_rot, uvPnt);

Malcolm

@username

Alright.

Cant you multiply a matrix and a float angle value there with an external uv?

I can see you attempt to call that in your last line, but I dont see the matrix with the sin and cos values in the 2 channels first slots. x and y.

I would have through you could just do this as well.

**Answer** by Malcolm Kesson
·
Sep 03 at 05:03 PM

This,

AtMatrix mat_rot = AiM4RotationZ(rotation);

should give me a matrix with the trig values that correspond to the (rotation) angle. I cannot see why using the AiM4VectorByMatrixMult function is not working?

This is the place for Arnold renderer users everywhere to ask and answer rendering questions, and share knowledge about using Arnold, Arnold plugins, workflows and developing tools with Arnold.

If you are a new user to Arnold Answers, please first check out our FAQ and User Guide for more information.

**When posting questions, please be sure to select the appropriate Space for your Arnold plugin and include the plugin version you are using. **

**Please include images, scene and log files whenever possible as this helps the community answer your questions. **

If you are looking for Arnold Documentation and Support please visit the Arnold Support site.

To try Arnold please visit the Arnold Trial page.

© 2009 - 2019 Solid Angle S.L. All Rights Reserved

- Anonymous
- Sign in
- Create
- Ask a question
- Spaces
- C4DtoA
- HtoA
- KtoA
- MtoA
- MAXtoA
- SItoA
- Arnold Core Renderer
- Arnold GPU Beta
- Development
- Shader Hacking
- Help
- Explore
- Topics
- Questions
- Users