Community
Arnold General Rendering Forum
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Equivalent vector/matrix function to OSL rotate()

5 REPLIES 5
Reply
Message 1 of 6
mkesson4VQY4
795 Views, 5 Replies

Equivalent vector/matrix function to OSL rotate()

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?

5 REPLIES 5
Message 2 of 6
madsd
in reply to: mkesson4VQY4

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)	
}
Message 3 of 6
mkesson4VQY4
in reply to: mkesson4VQY4

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

Message 4 of 6
madsd
in reply to: mkesson4VQY4

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.

Message 5 of 6
mkesson4VQY4
in reply to: mkesson4VQY4

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?

Message 6 of 6
mkesson4VQY4
in reply to: mkesson4VQY4

Mads.

This seems to be working OK.

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

Malcolm

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk Design & Make Report