change a function to use ogre procedural problem

dreamig

15-01-2013 08:31:37

Hi,
i had problem before and i resolved it :
it was relating two point by cylinder , i resolved it by creating cylinder manually
i want now use ogreprocedural
my first code (manually is)

createCylinder( Ogre::SceneNode *start, Ogre::SceneNode *end, float R,Ogre::String nom )
{
Ogre::Vector3 from = start->_getDerivedPosition();
Ogre::Vector3 to = end->_getDerivedPosition();
Ogre::Real Length = from.distance( to );

Ogre::Real step = Ogre::Radian( Ogre::Degree( 2 ) ).valueRadians();

std::vector< Ogre::Vector3 > bottom;
std::vector< Ogre::Vector3 > top;
//precalculate
for( Ogre::Real i =0; i < Ogre::Math::PI*2; i = i+step )
{
bottom.push_back( Ogre::Vector3( Ogre::Math::Sin( i )*R, 0 , Ogre::Math::Cos( i )*R ));
top.push_back( Ogre::Vector3( Ogre::Math::Sin( i )*R, Length , Ogre::Math::Cos( i )*R ));
}

Ogre:: ManualObject *cyl_bottom = mSceneMgr->createManualObject();
Ogre:: ManualObject *cyl_top = mSceneMgr->createManualObject();
Ogre:: ManualObject *cyl_side = mSceneMgr->createManualObject();

cyl_bottom->begin( "BaseWhiteNoLightning", Ogre::RenderOperation::OT_TRIANGLE_FAN );
cyl_top->begin( "BaseWhiteNoLightning",Ogre:: RenderOperation::OT_TRIANGLE_FAN );
cyl_side->begin( "BaseWhiteNoLightning", Ogre::RenderOperation::OT_TRIANGLE_STRIP ); // Side is triangle strip
size_t size = bottom.size();
//fill points
for( int i = 0; i < size; ++i )
{

cyl_bottom->position( bottom );
cyl_top->position( top );
cyl_side->position( top[ i ] );
cyl_side->position( bottom[ i ] );
}
count++;
cyl_bottom->end();
cyl_top->end();
cyl_side->end();

Ogre::SceneNode *cylin =start->createChildSceneNode(nom);

cylin->attachObject( cyl_bottom );
cylin->attachObject( cyl_top );
cylin->attachObject( cyl_side );
cylin ->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo( to-from ) );

it work and relat the point "start" and "end " without problem

BUT when i want use ogre procedural it does not work , i changed and i used "CapsuleGenerator()"

that's my code

Procedural::CapsuleGenerator().setRadius(40).setHeight(Length).realizeMesh("capsuleMesh");
Ogre::Entity* ent2 = mSceneMgr->createEntity("capsuleMesh");
Ogre::SceneNode* sn = /*mSceneMgr->getRootSceneNode()*/start->createChildSceneNode();
sn->attachObject(ent2);

sn->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo( to-from ) );


and that's what i see

mikachu

15-01-2013 18:08:29

This is rather undocumented (I should fix this), but the capsule is origin centered (whereas the cylinder is origin based), but you can circumvent that with the following code :

Procedural::CapsuleGenerator().setRadius(40).setHeight(Length).setPosition(0,Length/2,0).realizeMesh("capsuleMesh");

That will cause the capsule to be origin based, just like the cylinder..

dreamig

15-01-2013 21:04:38

yes it work i create two Capsule
BUT i have another problem in the view
look what i see

like you see , i can't make defference between the two capsule ,
i want to see them , for exemple like that

where there is empty between the two capsule

mikachu

16-01-2013 22:33:16

Actually, the capsule's height is the height of the cylinder part.
So you would have to take into account the spherical caps if you want the top of each sphere to meet points.

You can fix that by setting Length = distance between 2 points - radius

dreamig

17-01-2013 15:35:04

i make like that


Ogre::Real hei=Ogre::Math::Abs(length-40);

Procedural::CapsuleGenerator().setRadius(40).setHeight(/*Length*/hei).setPosition(0,Length/2,0).realizeMesh(nom);

look what i see

mikachu

17-01-2013 15:45:18

Yes, height must be >0.
If it's <=0 it means that your points are too close to each other.
In that case, you can either clamp the height to be slightly >0 (that will look like a sphere), or clamp the radius by the distance between two points.

dreamig

17-01-2013 16:07:05

i make like that


Ogre::Real hei=Ogre::Math::Abs(length-40);

Procedural::CapsuleGenerator().setRadius(40).setHeight(/*Length*/hei).setPosition(0,Length/2,0).realizeMesh(nom);

look what i see
http://www.hostingpics.net/viewer.php?id=53684069er.jpg

mikachu

17-01-2013 16:32:48

Ok, but what is your question?
I assume it doesn't look like what you thought it would...
But you have to provide me with more data, if you think there's something wrong : what is the value of length? Is Length == length? What's the distance between your 2 points?

dreamig

17-01-2013 17:08:55

Ok , that's the information:
1- i have many scene node and i create capsule between two scene node

create_capsule(node1,node2,40,"cap1" );
c(node2,node3, 40,"cap2" );

the create_capsule is like that

void QOgre create_capsule( Ogre::SceneNode *start, Ogre::SceneNode *end, float R,Ogre::String nom )
{



Ogre::Vector3 from = start->_getDerivedPosition()/*getPosition()*/;
Ogre::Vector3 to = end->_getDerivedPosition();
Ogre::Real Length = from.distance( to );
Procedural::CapsuleGenerator().setRadius(40).setHeight(Length).setPosition(0,Length/2,0).realizeMesh(nom);
Ogre::Entity* ent2 = mSceneMgr->createEntity(nom);
ent2->setMaterial(material3);
Ogre::SceneNode* sn = start->createChildSceneNode();
sn->attachObject(ent2);

sn->_setDerivedOrientation( Ogre::Vector3::UNIT_Y.getRotationTo( to-from ) );


that create to me two capsule like you see in my previeous reply
and like yo see too we can't made deference between the two capsule there is no edge
i just want make adge to see the two capsule good , not see them like one thing
]

mikachu

17-01-2013 20:40:16

You can try that :
Ogre::Real Length = from.distance( to );
Ogre::Real radius = Ogre::Math::Min(40, Length/2-0.1);
Ogre::Real height = Length - 2*radius;
Procedural::CapsuleGenerator().setRadius(radius).setHeight(height).setPosition(0,Length/2,0).realizeMesh(nom);

dreamig

17-01-2013 20:47:06

Ogre::Real radius = Ogre::Math::Min(40, Length/2-0.1);
there is no member in Ogre::math have name min

dreamig

17-01-2013 21:00:32

it work when i make
Ogre::Real height = Length - 2*40;
Procedural::CapsuleGenerator().setRadius(40).setHeight(height).setPosition(0,Length/2,0).realizeMesh(nom);

mikachu

17-01-2013 21:08:42

there is no member in Ogre::math have name min
My mistake, but there's a std::min instead...

it work when i make
Ogre::Real height = Length - 2*40;
Procedural::CapsuleGenerator().setRadius(40).setHeight(height).setPosition(0,Length/2,0).realizeMesh(nom);

good

Transporter

18-01-2013 09:13:54

Ogre::Real radius = std::min<Ogre::Real>(40, Length/2-0.1);