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: Setting a vector's length
View page
Source of version: 4
(current)
!!Overview of the problem You are writing some code that uses OGRE's great ''Ogre::Vector2'', ''Ogre::Vector3'' and ''Ogre::Vector4'' classes and then you need to arbitrarily set the length of the vector you are using. You look at OGRE's documentation, but then you scream out loud when you realize that OGRE does not define any function to set the length of a vector. As you are not a math genius (just as me) and/or you are never sure about yourself (just as mee too), you are desperate as you see that looking for some code in the forums gives you everything except what you are looking for. !!The solution The solution is really simple, just create a small function in your program, that takes a ''Ogre::Vector3'' pointer as the first parameter and a ''Ogre::Real'' as the second parameter, and you are done! {CODE(wrap="1", colors="c++")}void setVectorLength(Ogre::Vector3 *vector, const Ogre::Real newLength) { vector->normalise(); (*vector) *= newLength; }{CODE} You could write overloaded functions for ''Ogre::Vector2'' and ''Ogre::Vector4'' as well. {CODE(wrap="1", colors="c++")}void setVectorLength(Ogre::Vector2 *vector, const Ogre::Real newLength) { vector->normalise(); (*vector) *= newLength; } void setVectorLength(Ogre::Vector4 *vector, const Ogre::Real newLength) { vector->normalise(); (*vector) *= newLength; }{CODE}
Search by Tags
Search Wiki by Freetags
Latest Changes
Minimal Ogre Collision
Artifex Terra
OpenMB
Advanced Mogre Framework
MogreSocks
Critter AI
Mogre Add-ons
MOGRE
Mogre MyGUI wrapper
MOGRE Editable Terrain Manager
...more
Search
Find
Advanced
Search Help
Online Users
50 online users