Community
Arnold General Rendering Forum
abbrechen
Suchergebnisse werden angezeigt für 
Anzeigen  nur  | Stattdessen suchen nach 
Meintest du: 

Equivalent vector/matrix function to OSL rotate()

5 ANTWORTEN 5
Antworten
Nachricht 1 von 6
Anonymous
1113 Aufrufe, 5 Antworten

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 ANTWORTEN 5
Nachricht 2 von 6
madsd
als Antwort auf: Anonymous

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)	
}
Nachricht 3 von 6
Anonymous
als Antwort auf: Anonymous

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

Nachricht 4 von 6
madsd
als Antwort auf: Anonymous

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.

Nachricht 5 von 6
Anonymous
als Antwort auf: Anonymous

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?

Nachricht 6 von 6
Anonymous
als Antwort auf: Anonymous

Mads.

This seems to be working OK.

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

Malcolm

Sie finden nicht, was Sie suchen? Fragen Sie die Community oder teilen Sie Ihr Wissen mit anderen.

In Foren veröffentlichen  

Autodesk Design & Make Report