Find vector in radius around original vector

Get answers to all your basic programming questions. No Ogre questions, please!
Post Reply
Emphasis
Gnoblar
Posts: 7
Joined: Thu Oct 10, 2013 12:18 am

Find vector in radius around original vector

Post by Emphasis »

Hi all,

I have the following annoying problem. I have a mesh and on one of it's surface triangles I place an emitter. The surface normal is based on the 3 vertices of that triangle. So i have a vector for the emitter position and the normal aligning it with the surface triangle. Now what I want to do is find a vector around my emitter, preferably with varying X and Z coordinates but not Y. I can use the Spherical Coordinate System http://en.wikipedia.org/wiki/Spherical_ ... ate_system. Those axes are a little bit different from Ogre's so I need to adjust for that I think.

Anyway so I thought I would take the original emitter position and transform it to local space based on the emitter's scene node. That makes it have a vector of (0, 0, 0) which maybe isn't very useful. Using angles of 0 for theta and 90 for phi I might get a local offset vector of (1, 0, 0). Now somehow I need to apply that offset to my emitter position but also taking into account the positioning the emitter has with regards to the surface. I've literally tried about everything but I cannot get the right position. I need to do some world/local conversion somewhere but it hasn't been working out...

Image

This is the best I can do as far as drawing goes. I have the emitter (green) and want to get a position around it for a certain radius (r in the spherical coordinates). My Y-offset (in Ogre, Z in the wiki article) is preferably 0. So basically I'm looking for the position on a disc with radius r around the original emitter position but also possibly on the hemisphere. Plus accounting for the surface normal. I probably need a local system based on the surface normal but how do I acquire that? It's something about making the surface normal vector the Z-axis but...

My emitter's sceneNode is not oriented using the surface normal, but rather using the global X, Y and Z axes. So, if i orient the sceneNode using the surface normal as up vector I should be able to use convertWorldToLocalPosition that gives me a local coordinate system that I can use to determine the offset and then convert back to World...?

Any ideas? Really stuck on this getting the right results :/

Thanks!
Emphy
Dofter
Gnoblar
Posts: 16
Joined: Wed Jul 15, 2009 6:51 pm

Re: Find vector in radius around original vector

Post by Dofter »

As i do understand your question you first have to create a vector on a circle around the origin v=(r cos(phi), 0, r sin(phi)), if y is the normal axis for your circle. These are the local coordinates in the system of your emitter. So you have to calculate the world coords with convertLocaltoWorldcoords(v) if you want to get the coords in the system of the world.
Emphasis
Gnoblar
Posts: 7
Joined: Thu Oct 10, 2013 12:18 am

Re: Find vector in radius around original vector

Post by Emphasis »

What I don't understand is.. if I put in a radius of 10 I get this (local) offset vector for phi = 45 degrees: Vector3(7.07107, 0, 7.07107) with magnitude 10 (so that's good, it's r).

So that's quite a large offset I'm aware. But doing the convertLocalToWorld on my emitter node, well, it's Vector3(-7.48492, 21.8031, 3.68021) vs Vector3(-7.48533, 21.8081, 3.67963) for the original position and the offsetted one.

I did this for my emitter node:

Code: Select all

newEmitter->node->setDirection(faceNormal, Ogre::Node::TransformSpace::TS_LOCAL, Ogre::Vector3::NEGATIVE_UNIT_Y);   // Tried Z, TS_WORLD, TS_PARENT...

and also:

Ogre::Vector3 emitterYAxis = newEmitter->node->getOrientation().yAxis();
Ogre::Quaternion rotation = emitterYAxis.getRotationTo(faceNormal);
newEmitter->node->setOrientation(rotation);
How is that possible...

Edit for future generations: if you use local/world conversions, don't do it on a scene node that's been scaled... Ogre's standard cube mesh is huge so I set the scale of my node to 0.02. Ofcourse all values were drastically decimated to say the least.. wow, can't believe I didn't see that.
Post Reply