found the position of point to create cylinder

mielle

24-01-2013 15:25:18

Hi,
i Ogre Procedural to create simple shape "cylinder" where i spécifid the position of the first poition and the position of the last point and it work


Ogre::Vector3 point1 = start->_getPosition();
Ogre::Vector3 to = end->getPosition();
Length = from.distance( to );


BUT now my problem , is that somtimes i have not the position of the last point i have just the position and the orientation of the point1 and the length (the height of the cylinder) i have too the orientation of the last point
can i get the posiiton of the last point?

EDIT i know that i can draw my cylinder without knowing the position of the end point because we have the length , the problem not here but the last point of cylinder1 is the first point of cylinder 2 so i must know the position of the last point of each cylinder

did you understabd me please ?

mikachu

24-01-2013 15:42:07

You can either orient your sceneNode, or bake orientation into the mesh by using CylinderGenerator::setOrientation().

mielle

24-01-2013 15:48:01

You can either orient your sceneNode, or bake orientation into the mesh by using CylinderGenerator::setOrientation().
i did not understabnd what you mean here ?

the problem is that even for the first cylinder i can't draw it because i can't found how i set it's orientation
in my first code and to orient the cylinder i make like that

cylinder>_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo( point1->getposition()-point2->getposition() ) );

BUT now i haven't the psoition of the point2 ; i have just the orientation of the two pont and position of the point1

mielle

24-01-2013 16:05:57

i chaged
this line
cylinder->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo(point1->getposition()-point2->getposition() );

cylinder>->_setDerivedOrientation( point1->getOrientation() );
it does not work

mikachu

24-01-2013 16:49:05

i have just the orientation of the two pont and position of the point1
If you have the orientation, why don't you use it in setOrientation?
If it's in a Vector3 form (and not quaternion), you can do
Ogre::Vector3::UNIT_Y.getRotationTo(myOrientationVector)

mielle

24-01-2013 19:04:16

i have the orientation as quaternion
but the orientation that i have is the orientation of the first point

mikachu

24-01-2013 19:57:12

So what's the problem? Could you be more specific when you say "it does not work"?
BTW, setOrientation() is often preferred to _setDerivedOrientation(), I think..

mielle

24-01-2013 20:42:03

ok
when i make like that

test(Point1,Length,"cylinder1) );

where in test

Procedural::CylinderGenerator().setRadius(50).setHeight(length).realizeMesh(nom);
Ogre::Entity* ent = mSceneMgr->createEntity(nom);
Ogre::SceneNode* node= point1->createChildSceneNode();
node->attachObject(ent);
node->_setDerivedOrientation(point1->getOrientation())

that's what i obtained
http://www.hostingpics.net/viewer.php?id=621539cyl.jpg

even if i make
node->setOrientation(point1->getOrientation())

mikachu

25-01-2013 08:46:17

I still don't see very clearly what you're trying to achieve..
If I understand correctly, you have one scenenode "point1" from which you want to display a cylinder.
The direction of the cylinder is either given by another point "point2", as you show on the picture, or by a know orientation.
And you want only 1 function to handle both cases.
Then, if you don't get the expected result, it's probably that orientation of point1 is not correctly computed (and that's outside the code snippet you showed me)

mielle

25-01-2013 09:10:17

If I understand correctly, you have one scenenode "point1" from which you want to display a cylinder.
yes , that's what i want , i have the position, orientation of the point1 , i have the length of the cylinder and i want display the cylinder .

NOTE : just to test if my code work , i add another scenenode sphere , where it must be the point2
and i see that my code do not work

Then, if you don't get the expected result, it's probably that orientation of point1 is not correctly computed
so you mean that the orientation of point1 not good ?
i had euler angle (x,y,z) and i calculate the quaternion using this function

EulerToOgreQuat( const Ogre::Vector3& degreesVector )
{
Ogre::Matrix3 mx;
mx.FromEulerAnglesXYZ
(Ogre::Degree(degreesVector.x/), Ogre::Degree(degreesVector.y), Ogre::Degree(degreesVector.z/));
Ogre::Quaternion result(mx);
return result;
}

so maybe this function is wrong and do not give me the orientation ?

mielle

25-01-2013 09:18:08

i have an another idea
can i get the position of the position of point2 using just the position orientation of point1 and the length ?
if we get this position i can makke like that
cylinder->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo(point1->getposition()-point2->getposition() );
No?
but how i can get this position ?

Transporter

25-01-2013 09:45:20

i know that i can draw my cylinder without knowing the position of the end point because we have the length , the problem not here but the last point of cylinder1 is the first point of cylinder 2 so i must know the position of the last point of each cylinder
So, you like to create a kind of a chain, right? Well, it's quite simple, something like:

point2 = point1 + (uv * rot) * length

  1. Create an unit vector[/*:m]
  2. Rotate the unit vector with given rotation *[/*:m]
  3. Multiply unit vector with given length[/*:m]
  4. Add the result to the position of point1[/*:m][/list:o]

    * If you like to use euler angles you don't need a quaternion. You can use a Matrix3 with rotation information (http://en.wikipedia.org/wiki/Rotation_matrix).

mielle

25-01-2013 10:15:58

Hi
here i will show you my test to see the problem and maybe you find with me the solution
test1
i have the position of the point1 and the position of the point2 and i draw my cylinder like that

Point1= mSceneMgr->getRootSceneNode()->createChildSceneNode("point1",Ogre::Vector3(283.6,f882.6,160.5));
Point2=Point1->createChildSceneNode("point2");
Point2->_setDerivedPosition(482.07, 644.8,170.3)
Ogre::Real Length = Point1->getPosition.distance( Point2->_getDerivedPosition() );
Procedural::CylinderGenerator().setRadius(50).setHeight(length).realizeMesh("cylinder1");
Ogre::Entity* ent = mSceneMgr->createEntity("cylinder1");
Ogre::SceneNode* node= Point1->createChildSceneNode();
node->attachObject(ent);

node->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo(Point1->_getDerivedPosition()-point2->_getDerivedPosition() );
cout<<node->_getDerivedOrientation()

WITH THIS CODE I SEE CYLINDER DE POINT1 TO POINT2
the orientation of the cylinder is
quaternion<0.38,0,0,-0.92>

test2
<ith the same length and the same point1 position and information (orientation too) i make

Procedural::CylinderGenerator().setRadius(50).setHeight(length).realizeMesh("cylinder1");
Ogre::Entity* ent = mSceneMgr->createEntity("cylinder1");
Ogre::SceneNode* node= Point1->createChildSceneNode();
node->attachObject(ent);

node->_setDerivedOrientation( Point1->_getDerivedOrientation());
cout<<node->_getDerivedOrientation()

i see like the picture in my first reply and the orientation of the cylinder is
quaternion<1,0,0,0>
if i change the euler angle orientation of the point1 are :( 4.8,-2.3,-1.6) and using EulerToOgreQuat i get this quaternion
quaternion<0.99,-4.49 e-0.06,0.014,0.09)


SO i can't see where is the problem exactelly and why in my test2 the cylindre do not have the same direction as in test1

mielle

25-01-2013 10:23:13

"Transporter" i just see your reply
you mean to get the position of the point2 i make like that ?
point2 = point1 + (uv * rot) * length

Create an unit vector
Rotate the unit vector with given rotation *
Multiply unit vector with given length
Add the result to the position of point1


rot : is the quaternion of the point1?, and uv i can make it 0.2 for exemple ?
* If you like to use euler angles you don't need a quaternion. You can use a Matrix3 with rotation information (http://en.wikipedia.org/wiki/Rotation_matrix).
but it's better to use the quaternion no ? because we can rotate scenenode using quaternion it's better

Transporter

25-01-2013 10:42:01

you mean to get the position of the point2 i make like that ?
point2 = point1 + (uv * rot) * length

Create an unit vector
Rotate the unit vector with given rotation *
Multiply unit vector with given length
Add the result to the position of point1


rot : is the quaternion of the point1?

point2: Result (Vector3)
point1: Source position (Vector3)
uv: Unit vector (Vector3) with a length of 1
rot: Rotation object (Matrix3 or Quaternion)
length: Distance between point1 and point2 (Real)

How is this working? A unit vector has a length of 1. You should rotate it to the direction of your cylinder. After multipling it with the cylinder length, you have the vector of the cylinder's rotation axis. If you add this axis to the stat point you'll get the end point.

mielle

25-01-2013 11:23:47

i have two stuped questions :
1- i have the 3 angle of point1 in vector3 so how can i create the matrix using


Ogre Vector3 rot
Ogre::Matrix4 mat= (Ogre::Math::Cos rot[0]>,-Ogre::Math::Sun rot[1],Ogre::Math::Sun rot[2],Ogre::Math::Cos rot[3])

(i know its very stuped but i never create rotation matrix)
2- if i have rotation matrix of the point1 , and the cylinder is attached to point1 we can said that cylinder1 rotation is the same as pont1 rotation
so
"rot: Rotation object (Matrix3 or Quaternion)" is the rotation of point1

Transporter

25-01-2013 12:46:50

2- if i have rotation matrix of the point1 , and the cylinder is attached to point1 we can said that cylinder1 rotation is the same as pont1 rotation
so
"rot: Rotation object (Matrix3 or Quaternion)" is the rotation of point1

Yes, you can use the rotation of point1. If you like to setup a rotation matrix and not a quaternion, have a look at the matrix R at http://en.wikipedia.org/wiki/Rotation_m ... _rotations. You can copy these matrix to Ogre.

mielle

25-01-2013 13:57:14

If you like to setup a rotation matrix and not a quaternion, have a look at the matrix R at http://en.wikipedia.org/wiki/Rotation_m ... _rotations. You can copy these matrix to Ogre.
it's difficult to create matrix rotation using my three angle (vector3) so i will use this function better , where dereesVector represet my theree angle in degree

Ogre::Quaternion QOgreWidget::EulerToOgreQuat( const Ogre::Vector3& degreesVector )
{
Ogre::Matrix3 mx;
mx.FromEulerAnglesXYZ
(Ogre::Degree(degreesVector.x), Ogre::Degree(degreesVector.y), Ogre::Degree(degreesVector.z));
Ogre::Quaternion result(mx);
return result;
}


but it does not work cooerctly , i used three
that's my code
in create_scene

Point1= mSceneMgr->getRootSceneNode()->createChildSceneNode("point1",Ogre::Vector3(283.6,f882.6,160.5));
Point2=Point1->createChildSceneNode("point2");
Point2->_setDerivedPosition(482.07, 644.8,170.3)
Point3=Point2->createChildSceneNode("point3");
Point4=Point3->createChildSceneNode("point4");
//set derived position point3
//set derived position point4
Ogre::Real Length = Point1->_getDerivedPosition.distance( Point2->_getDerivedPosition() );
Ogre::Real Length1 = Point2->_getDerivedPosition.distance( Point3->_getDerivedPosition() );
Ogre::Real Length2 = Point3->_getDerivedPosition.distance( Point4->_getDerivedPosition() );
test(point1,Rot,Length)
test(point2,Rot1,Length1)
test(point3,Rot2,Length2)

in test

test(Ogre::SceneNode *start, Ogre::Vector3 end,Ogre::Real length )
{
[b][color=#FF0000]Ogre::Vector3 uv=Ogre::Vector3(0,1,0);
Ogre::Vector3 from = start->_getDerivedPosition();
Ogre::Quaternion quat=EulerToOgreQuat(end);
Ogre::Vector3 endd = from + ( quat*uv) * length;
float temp;
temp=endd.z;
endd.z=endd.x;
endd.x=endd.y;
endd.y=temp;[/color][/b]

Procedural::CylinderGenerator().setRadius(50).setHeight(length).realizeMesh("cylinder1"+number);
number++;
Ogre::Entity* ent = mSceneMgr->createEntity("cylinder1");
Ogre::SceneNode* node= Start->createChildSceneNode();
node->attachObject(ent);
[b][color=#FF0000]
node->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo( endd-from ) );[/color][/b]

screen short what i see
http://www.hostingpics.net/viewer.php?id=914020cyler.jpg
where the first cylinder is in green

mielle

25-01-2013 15:47:47

I think that the orientation angle of the cylinder is not the same angle as the angle of point1
why ?
lest's said that we have theree point point1 , point2 and point3 and we want draw cylinder frome point1 to point2 and from point1 to point3

if we consider that the cylinder has the same angle as point1 , we obtained 2 cylinder in the same direction and that's wrong
like this picture

http://www.hostingpics.net/viewer.php?id=324933testt.jpg

the both of the cylinder have the same direction
am i worng ? if no what it the solution

mielle

26-01-2013 09:59:21

my idea to get the position of point2 is wrong ? and for that the position of point2 that i calculated has not the same position as the point2 where it must to be ?
or because point2=point1->createchiledescenenode()
or because my eulertoquaternion is wrong .......

i can't found where is the problem exactelly , please see with me again the code

Transporter

27-01-2013 12:15:43


void TutorialApplication::createScene(void)
{
/*** setup environment ***/
// scene manager
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.9f, 0.9f, 0.9f));

// materials
Ogre::ResourceGroupManager::getSingleton().createResourceGroup("Colours");
Ogre::MaterialPtr red = Ogre::MaterialManager::getSingleton().create("red", "Colours");
red->setReceiveShadows(false);
red->getTechnique(0)->setLightingEnabled(true);
red->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue::Red);
red->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue::Red);
red->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue::Red);
Ogre::MaterialPtr green = Ogre::MaterialManager::getSingleton().create("green", "Colours");
green->setReceiveShadows(false);
green->getTechnique(0)->setLightingEnabled(true);
green->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue::Green);
green->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue::Green);
green->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue::Green);
Ogre::MaterialPtr blue = Ogre::MaterialManager::getSingleton().create("blue", "Colours");
blue->setReceiveShadows(false);
blue->getTechnique(0)->setLightingEnabled(true);
blue->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue::Blue);
blue->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue::Blue);
blue->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue::Blue);

/*** setup geometry **/
std::vector<Ogre::Real> joints;
std::vector<Ogre::Real> links;
std::vector<Ogre::Real> radians;

// cylinder radians
radians.push_back(2.0f);
radians.push_back(1.5f);
radians.push_back(1.0f);

// joint angles
joints.push_back(60.0f);
joints.push_back(30.0f);
joints.push_back(10.0f);

// link lengths
links.push_back(70.0f);
links.push_back(30.0f);
links.push_back(15.0f);

/*** create geometry ***/
Ogre::Vector3 nodePosition = Ogre::Vector3::ZERO;
Ogre::Matrix3 transform(-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
Procedural::SphereGenerator().setRadius(4.0f).realizeMesh("sphereMesh");
for(size_t i = 0; i < joints.size(); i++)
{
Ogre::String name = "cylinder" + Ogre::StringConverter::toString(i + 1);
Procedural::CylinderGenerator().setHeight(links).setRadius(radians).realizeMesh(name);
Ogre::SceneNode* sceneNode = mSceneMgr->getRootSceneNode()->createChildSceneNode();
Ogre::Entity* entityCylinder = mSceneMgr->createEntity(name);
entityCylinder->setMaterialName("green");
sceneNode->attachObject(entityCylinder);
Ogre::Entity* entitySphere = mSceneMgr->createEntity("sphereMesh");
entitySphere->setMaterialName("red");
sceneNode->attachObject(entitySphere);
sceneNode->setPosition(nodePosition);

Ogre::Matrix3 mx;
mx.FromEulerAnglesXYZ(Ogre::Degree(0.0f), Ogre::Degree(0.0f), Ogre::Degree(joints));
sceneNode->setOrientation(Ogre::Quaternion(mx));
nodePosition = nodePosition + (Ogre::Vector3(0.0f, links, 0.0f) * mx) * transform;
}
}

mielle

27-01-2013 17:38:01

Hi,
great you get it with those few informations
as i see it work BUT i have some question
/*** setup geometry **/
std::vector<Ogre::Real> joints;
std::vector<Ogre::Real> links;
std::vector<Ogre::Real> radians;

"radians"is the raduis of the cylinder (when i see the code i get thet is the raduis of the cylinder )i want just to confirm
the vector Joints represent the angle of each joint ? if yes why there is one angle there (we must had angle in x,y and z)
Ogre::Matrix3 transform(-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
how you set it ? why axactelly the matrix have this numbers ?
mx.FromEulerAnglesXYZ(Ogre::Degree(0.0f), Ogre::Degree(0.0f), Ogre::Degree(joints));
why we make x,y as 0 ? can we initialise joint as vector3 wehere they are x degree,ydegree and z degree

can you please explain to me this ligne what it mean ? i know is to found the position
nodePosition = nodePosition + (Ogre::Vector3(0.0f, links[i], 0.0f) * mx) * transform

Transporter

27-01-2013 19:03:54

So many question :D
/*** setup geometry **/
std::vector<Ogre::Real> joints;
std::vector<Ogre::Real> links;
std::vector<Ogre::Real> radians;

"radians"is the raduis of the cylinder (when i see the code i get thet is the raduis of the cylinder )i want just to confirm
the vector Joints represent the angle of each joint ? if yes why there is one angle there (we must had angle in x,y and z)

Yes, correct. I've made the example just for angles in one direction for a quick & dirty demonstration.

Ogre::Matrix3 transform(-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);
how you set it ? why axactelly the matrix have this numbers ?

This is a slightly modified identity matrix. You should read a good book about linear algebra. If you have a vector v and an identity matrix I the result from v*I is equal to v, that means an identity matrix doesn't change anything. Now I changed the first number from 1.0f to -1.0f which flips the x axis.
-1 0 0
0 1 0
0 0 1

Remember OGRE's coordinate system

which is not equal to a system like

you might use on paper.

mx.FromEulerAnglesXYZ(Ogre::Degree(0.0f), Ogre::Degree(0.0f), Ogre::Degree(joints));
why we make x,y as 0 ? can we initialise joint as vector3 wehere they are x degree,ydegree and z degree

Yes, of course you can use a Vector3 with all three rotations. I've made just a quick & dirty example.

can you please explain to me this ligne what it mean ? i know is to found the position
nodePosition = nodePosition + (Ogre::Vector3(0.0f, links, 0.0f) * mx) * transform

New position = old position + ((vector of cylinder length) * rotation matrix) * transformation with modified identity matrix

mielle

28-01-2013 00:14:29

HI again ,
i tested it BUT it does not work in my case !!!!!!!!!!!!!!!!! :|
in my case , firstly i have just ROOT point , then when i create cylinder i attach it to the point1 (or the root in the first time) then result spherenode too are attached to the point1 when i excute i obtain the two cylinder in the same direction !! (cylinder two on the cylinder one)
that's the code :


void TutorialApplication::createScene(void)
{
links.push_back(20);
links.push_back(30);
links.push_back(50);

links.push_back(20);
links.push_back(30));
links.push_back(50);
transform= Ogre::Matrix3(-1.0f, 0.0f, 0.0f, 0.0f, 1.0f, 0.0f, 0.0f, 0.0f, 1.0f);

/*** create geometry ***/
// std::vector<Ogre::SceneNode*> nodes;
Procedural::SphereGenerator().setRadius(30.0f).realizeMesh("sphereMesh");
Ogre::Entity* entitySphere = mSceneMgr->createEntity("sphereMesh");

nodePosition = Ogre::Vector3( 283.660, 882.638 ,160.520 );

Ogre::SceneNode* rthi= test(ROOT,links[0],Ogre::Vector3((Ogre::Vector3(4.836,-2.30,-1.692))),"rhi");
Ogre::SceneNode* lthi= test(ROOT,links[5],Ogre::Vector3((Ogre::Vector3(4.836,-2.30,-1.692)),"lhi");
}

and in test


Ogre::SceneNode* TutorialApplication:::test(Ogre::SceneNode *start,Ogre::Real length,Ogre::Vector3 joint, Ogre::String nom )
{
// Ogre::String name = "cylinder" + Ogre::StringConverter::toString(i + 1);
Procedural::CylinderGenerator().setHeight(length).setRadius(50).realizeMesh(nom);
Ogre::SceneNode* sceneNode = start->createChildSceneNode();
Ogre::Entity* entityCylinder = mSceneMgr->createEntity(nom);
entityCylinder->setMaterialName("green");
sceneNode->attachObject(entityCylinder);
Ogre::Entity* entitySphere = mSceneMgr->createEntity("sphereMesh");
Ogre::SceneNode* nodesphere = start->createChildSceneNode();
entitySphere->setMaterial(material1);
// nodesphere->setOrientation(
// nodesphere->setPosition(nodePosition);
nodes.push_back(nodesphere);
//sceneNode->attachObject(entitySphere);
sceneNode->_setDerivedPosition(nodePosition);

Ogre::Matrix3 mx;
mx.FromEulerAnglesXYZ(/*Ogre::Degree(0.0f)*/Ogre::Degree(joint.x), /*Ogre::Degree(0.0f)*/Ogre::Degree(joint.y), Ogre::Degree(joint.z));
sceneNode->setOrientation(Ogre::Quaternion(mx));
nodePosition = nodePosition + (Ogre::Vector3(0.0f,/* links*/length, 0.0f) * mx) * transform;

return nodesphere/*nodeposition*/;
}



Maybe because they have the same Orientation ?
i used _setderivedposition because i want that the point2 is attached to point1(start) and the cylinder is attached to start point too

MY PROBLEM IS HERE , because if you see in my reply i said that the cylinder is attached to point1

Transporter

28-01-2013 10:04:46

i used _setderivedposition because i want that the point2 is attached to point1(start) and the cylinder is attached to start point too

MY PROBLEM IS HERE , because if you see in my reply i said that the cylinder is attached to point1

:oops: I'm sorry I missed that fact during quick reading.

If node point2 is a childnode of node point1 it's really easy. You only have to put the next node on top of the current cylinder (link).

Here is a new example, working in 3D and with coordinate frame:

void TutorialApplication::createScene(void)
{
/*** setup environment ***/
// scene manager
mSceneMgr->setAmbientLight(Ogre::ColourValue(0.9f, 0.9f, 0.9f));

// materials
Ogre::ResourceGroupManager::getSingleton().createResourceGroup("Colours");
Ogre::MaterialPtr red = Ogre::MaterialManager::getSingleton().create("red", "Colours");
red->setReceiveShadows(false);
red->getTechnique(0)->setLightingEnabled(true);
red->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue::Red);
red->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue::Red);
red->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue::Red);
Ogre::MaterialPtr green = Ogre::MaterialManager::getSingleton().create("green", "Colours");
green->setReceiveShadows(false);
green->getTechnique(0)->setLightingEnabled(true);
green->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue::Green);
green->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue::Green);
green->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue::Green);
Ogre::MaterialPtr blue = Ogre::MaterialManager::getSingleton().create("blue", "Colours");
blue->setReceiveShadows(false);
blue->getTechnique(0)->setLightingEnabled(true);
blue->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue::Blue);
blue->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue::Blue);
blue->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue::Blue);
Ogre::MaterialPtr yellow = Ogre::MaterialManager::getSingleton().create("yellow", "Colours");
yellow->setReceiveShadows(false);
yellow->getTechnique(0)->setLightingEnabled(true);
yellow->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue(1.0f, 1.0f, 0.0f));
yellow->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue(1.0f, 1.0f, 0.0f));
yellow->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue(1.0f, 1.0f, 0.0f));
Ogre::MaterialPtr cyan = Ogre::MaterialManager::getSingleton().create("cyan", "Colours");
cyan->setReceiveShadows(false);
cyan->getTechnique(0)->setLightingEnabled(true);
cyan->getTechnique(0)->getPass(0)->setDiffuse(Ogre::ColourValue(0.0f, 1.0f, 1.0f));
cyan->getTechnique(0)->getPass(0)->setAmbient(Ogre::ColourValue(0.0f, 1.0f, 1.0f));
cyan->getTechnique(0)->getPass(0)->setSelfIllumination(Ogre::ColourValue(0.0f, 1.0f, 1.0f));

/*** setup geometry **/
std::vector<Ogre::Vector3> joints;
std::vector<Ogre::Real> links;
std::vector<Ogre::Real> radians;

// cylinder radians
radians.push_back(3.0f);
radians.push_back(2.5f);
radians.push_back(2.0f);
radians.push_back(1.5f);
radians.push_back(1.0f);
radians.push_back(0.5f);

// joint angles
joints.push_back(Ogre::Vector3(47.0f, 33.0f, 2.0f));
joints.push_back(Ogre::Vector3(9.0f, 45.0f, 3.0f));
joints.push_back(Ogre::Vector3(23.0f, 52.0f, 56.0f));
joints.push_back(Ogre::Vector3(53.0f, 80.0f, 60.0f));
joints.push_back(Ogre::Vector3(33.0f, 16.0f, 15.0f));
joints.push_back(Ogre::Vector3(86.0f, 75.0f, 5.0f));

// link lengths
links.push_back(100.0f);
links.push_back(80.0f);
links.push_back(60.0f);
links.push_back(40.0f);
links.push_back(20.0f);
links.push_back(10.0f);

/*** create coordinate frame ***/
Procedural::Path p;
Procedural::Shape cs = Procedural::CircleShape().realizeShape();
Ogre::SceneNode* snCoordinateSystem = mSceneMgr->getRootSceneNode()->createChildSceneNode();

p = Procedural::Path().addPoint(Ogre::Vector3::ZERO).addPoint(500.0f * Ogre::Vector3::UNIT_X);
Procedural::Extruder().setExtrusionPath(&p).setShapeToExtrude(&cs).realizeMesh("XAxis");
Ogre::Entity* entXAxis = mSceneMgr->createEntity("XAxis");
Ogre::SceneNode* snXAxis = snCoordinateSystem->createChildSceneNode();
snXAxis->attachObject(entXAxis);
entXAxis->setMaterialName("red", "Colours");
entXAxis->setCastShadows(false);

p = Procedural::Path().addPoint(Ogre::Vector3::ZERO).addPoint(500.0f * Ogre::Vector3::UNIT_Y);
Procedural::Extruder().setExtrusionPath(&p).setShapeToExtrude(&cs).realizeMesh("YAxis");
Ogre::Entity* entYAxis = mSceneMgr->createEntity("YAxis");
Ogre::SceneNode* snYAxis = snCoordinateSystem->createChildSceneNode();
snYAxis->attachObject(entYAxis);
entYAxis->setMaterialName("green", "Colours");
entYAxis->setCastShadows(false);

p = Procedural::Path().addPoint(Ogre::Vector3::ZERO).addPoint(500.0f * Ogre::Vector3::UNIT_Z);
Procedural::Extruder().setExtrusionPath(&p).setShapeToExtrude(&cs).realizeMesh("ZAxis");
Ogre::Entity* entZAxis = mSceneMgr->createEntity("ZAxis");
Ogre::SceneNode* snZAxis = snCoordinateSystem->createChildSceneNode();
snZAxis->attachObject(entZAxis);
entZAxis->setMaterialName("blue", "Colours");
entZAxis->setCastShadows(false);

/*** create geometry ***/
Ogre::Vector3 nodePosition = Ogre::Vector3::ZERO;
Procedural::SphereGenerator().setRadius(4.5f).realizeMesh("sphereMesh");
Ogre::SceneNode* parentNode = mSceneMgr->getRootSceneNode();
for(size_t i = 0; i < joints.size(); i++)
{
Ogre::String name = "cylinder" + Ogre::StringConverter::toString(i + 1);
Procedural::CylinderGenerator().setHeight(links).setRadius(radians).realizeMesh(name);
Ogre::SceneNode* pointNode = parentNode->createChildSceneNode("pointNode" + Ogre::StringConverter::toString(i + 1));
Ogre::Entity* entityCylinder = mSceneMgr->createEntity(name);
entityCylinder->setMaterialName("cyan");
pointNode->attachObject(entityCylinder);
Ogre::Entity* entitySphere = mSceneMgr->createEntity("sphereMesh");
entitySphere->setMaterialName("yellow");
pointNode->attachObject(entitySphere);

pointNode->setPosition(nodePosition);
Ogre::Quaternion mx = Ogre::Quaternion(Ogre::Degree(joints.y), Ogre::Vector3::UNIT_Y) * Ogre::Quaternion(Ogre::Degree(joints.x), Ogre::Vector3::UNIT_X) * Ogre::Quaternion(Ogre::Degree(joints.z), -Ogre::Vector3::UNIT_Z);
pointNode->setOrientation(Ogre::Quaternion(mx));

nodePosition = Ogre::Vector3(0.0f, links, 0.0f);
parentNode = pointNode;
}
}

I use a different way to calculate the orientation, see http://www.ogre3d.org/tikiwiki/tiki-ind ... ngle+Class

dreamig

31-01-2013 16:28:47

Hi Transporter ,
i read your reply
This is a slightly modified identity matrix. You should read a good book about linear algebra. If you have a vector v and an identity matrix I the result from v*I is equal to v, that means an identity matrix doesn't change anything. Now I changed the first number from 1.0f to -1.0f which flips the x axis.
the ogre coordiante system is like that

you said that it's not eqaul to system like that


i dot not underant 2 things
1-how you konw that the cylinder created by "mielle" has thie seconde coordiante system and not ogre's system, because i undrestand you said that because the cylinder coordiante system is not has not the same as ogre coordiante sytem for that you flips x in the identity matrix
2-when we see the two photos , we see that x in ogre coordinaate system do not equal to (-x) in the other coordinate system