OGRE Wiki
Support and community documentation for Ogre3D
Ogre Forums
ogre3d.org
Log in
Username:
Password:
CapsLock is on.
Remember me (for 1 year)
Log in
Home
Tutorials
Tutorials Home
Basic Tutorials
Intermediate Tutorials
Mad Marx Tutorials
In Depth Tutorials
Older Tutorials
External Tutorials
Cookbook
Cookbook Home
CodeBank
Snippets
Experiences
Ogre Articles
Libraries
Libraries Home
Alternative Languages
Assembling A Toolset
Development Tools
OGRE Libraries
List of Libraries
Tools
Tools Home
DCC Tools
DCC Tutorials
DCC Articles
DCC Resources
Assembling a production pipeline
Development
Development Home
Roadmap
Building Ogre
Installing the Ogre SDK
Setting Up An Application
Ogre Wiki Tutorial Framework
Frequently Asked Questions
Google Summer Of Code
Help Requested
Ogre Core Articles
Community
Community Home
Projects Using Ogre
Recommended Reading
Contractors
Wiki
Immediate Wiki Tasklist
Wiki Ideas
Wiki Guidelines
Article Writing Guidelines
Wiki Styles
Wiki Page Tracker
Ogre Wiki Help
Ogre Wiki Help Overview
Help - Basic Syntax
Help - Images
Help - Pages and Structures
Help - Wiki Plugins
Toolbox
Freetags
Categories
List Pages
Structures
Trackers
Statistics
Rankings
List Galleries
Ogre Lexicon
Comments
History: RotatingATextureUsingGetYaw
View page
Source of version: 3
(current)
In this code I'm assuming you want to work with a flat-XZ rotation. You can also do this with a flat-YZ or a flat-XY rotation, but then you will need to use quaternion.getPitch() or quaternion.getRoll(). Also be careful because I think it will not return a value between 90 & -90 but 0 & 180, so then you will need the edit the part where I check for the camera direction. {CODE(wrap="1", colors="c++")} // Get CamDirection and cancel out Y-Axis and Magnitude Vector3 vCamDirection = mCamera->getDerivedOrientation() * Vector3::NEGATIVE_UNIT_Z; vCamDirection.y = 0; vCamDirection.normalise(); // Get rotations to X-Axis & Z-Axis Quaternion qRotationToXAxis = vCamDirection.getRotationTo( Vector3::UNIT_X ); Quaternion qRotationToZAxis = vCamDirection.getRotationTo( Vector3::UNIT_Z ); // Get the degrees from both rotations Real rRotationToXAxis = qRotationToXAxis.getYaw().valueDegrees(); Real rRotationToZAxis = qRotationToZAxis.getYaw().valueDegrees(); Real rRotation = 0; // Check which direction the camera is looking // And adjust rRotation if needed if( rRotationToXAxis >= 0 ) { rRotation = rRotationToZAxis; } else { if( rRotationToZAxis >= 0 ) { rRotation = rRotationToZAxis - rRotationToXAxis * 2; } else { rRotation = rRotationToZAxis + rRotationToXAxis * 2; } } // Rotate Texture TextureUnitState *texture = eCamView->getMaterial()->getTechnique(0)->getPass(0)->getTextureUnitState(0); texture->setTextureRotate( Degree( -rRotation ) );{CODE} In this part: {CODE(wrap="1", colors="c++")} ... if( rRotationToXAxis >= 0 ) { rRotation = rRotationToZAxis; } else { if( rRotationToZAxis >= 0 ) { rRotation = rRotationToZAxis - rRotationToXAxis * 2; } else { rRotation = rRotationToZAxis + rRotationToXAxis * 2; } } ...{CODE} I'm figuring out if the camera is looking along the Z-Axis (in positive direction) and if so I just use the rotation to the Z-Axis, but when the camera is looking the other way you will have to add or subtract the rotation from the X-Axis to be able to rotate 180 degrees. Whether to add or to subtract depends if you are looking in a positive direction along side the X-Axis or not. When the camera is pointing in the negative direction of the Z-Axis, rRotationFromZAxis will still give you a value between 90 & -90. Now to compensate for that, you just multiply rRotationsFromXAxis by 2. Original Author: Joost Passon, Release Date: January 5th, 2006
Search by Tags
Search Wiki by Freetags
Latest Changes
Overlay Editor
Introduction - JaJDoo Shader Guide - Basics
RT Shader System
RapidXML Dotscene Loader
One Function Ogre
IDE Eclipse
FMOD SoundManager
HDRlib
Building Ogre V2 with CMake
Ogre 2.1 FAQ
...more
Search
Find
Advanced
Search Help
Online Users
95 online users