## Recommended Posts

Tonight I've been looking for a way to rotate a texture 360 degrees from the center so I can use it on a model sheet. I've only found ex_texcoords0 which pans the texture on the face, but I can't seem to find any values or clues on how I would rotate the texture on the face. Any pointers in the right direction would be appreciated.

You can apply a 2x2 rotation matrix to the texcoords, something like this would rotate the texture :

Â

```		    float sinx = sin ( 0.0001 * currenttime );
float cosx = cos ( 0.0001 * currenttime );
float siny = sin ( 0.0001 * currenttime );
mat2 rotmatrix =  mat2( cosx, -sinx, siny, cosx);
vec2 rotuv = rotmatrix*ex_texcoords0;```

Â

Then use rotuv instead of ex_texcoords0 when you lookup the texture.

if you just need a fast 90 degree or 180 rotation, you can switch ex_texoords0.xy with yx and -xy -yx etc..

Thanks, now I just need to figure out how to make it spin from the center for the plane/texture than the front corner. I kind of want to do a spinning animation on my cubes in Vectronic.

Â

Edit: No luck so far, I just keep getting effects that reminds me of the Giygas boss battle from EarthBound. I guess I still need help.

Ah center rotation, just subtract 0.5 from coordinates, rotate and add 0.5.

Like this :

Â

``` //find center
vec2 uv = (ex_texcoords0-0.5);

//rotate
float sinx = sin ( 0.001 * currenttime );
float cosx = cos ( 0.001 * currenttime );
float siny = sin ( 0.001 * currenttime );
mat2 rotmatrix = mat2( cosx, -sinx, siny, cosx);

//apply matrix and restore uv (0.5)
vec2 rotuv = rotmatrix*uv+0.5;

//fetch texture using new uv coordinates
outcolor *= texture(texture0,rotuv);```

How cool. This will suit my 'Click-To-Go' marker perfectly. Was just wondering how to solve that and here is a solution like sent from heaven.

Shadmar, you're a hero. Just a tip, make sure that the texture file is Clamped to X and Y to remove the duplicate textures you see in the corners while it's rotating. Now to test my idea with this. Thanks again.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
• ### Recent Topics

• #### Hide or Delete Image (context) command in LUA??

By Russell, in Programming

• 2 replies
• 27 views
• #### One more try.

By ðŸ’ŽYueðŸ’Ž, in Off-topic

• 6 replies
• 123 views
• #### The Disinformation Superhighway

By Josh, in Off-topic

• 18 replies
• 370 views
• #### Small Code Demo

By reepblue, in Showcase

• 0 replies
• 99 views
• #### Modify terrain in game?

By Marcousik, in Programming

• 0 replies
• 70 views
Ã—

• Pages

• Back
• Store

• #### Support

• Projects
Ã—
• Create New...