View unanswered posts | View active topics It is currently Mon Jul 06, 2020 8:19 am



Reply to topic  [ 3 posts ] 
 How to create bounding box around object / mesh 
Author Message

Joined: Thu Jun 28, 2012 8:03 am
Posts: 1
Post How to create bounding box around object / mesh
Hello all
im beginner to the lib and opengl , ( its great ) .
i like to make visible bounding box around simple loaded mesh . where should i start ?
is there any tutorial or direction i should read ?
Thanks


Thu Jun 28, 2012 12:35 pm
Profile
Site Admin

Joined: Sun Jan 03, 2010 4:27 pm
Posts: 390
Post Re: How to create bounding box around object / mesh
Hello,
umen wrote:
i like to make visible bounding box around simple loaded mesh . where should i start ?

To view a bounding box, you have to create and render a GLC_Box from the bounding box you want to view.
If you load a mesh from a file, GLC_lib build a GLC_World. A GLC_World is a structured 3D scene.

Ok, let see a step by step procedure :
    Load the 3D Scene
    Create the box from the bounding box of the scene
    Change or modify the material of the created box to make it transparent
    Render the content of your 3DViewCollection after the world

A construction sample code (from example 6) :
Code:
void GLWidget::CreateScene()
{
   // Load mesh from a file
   QFile manFile(":man.obj");
   m_World= GLC_Factory::instance()->createWorldFromFile(manFile);

   // Create GLC_Box from a Bounding box
   GLC_3DViewInstance box(GLC_Factory::instance()->createBox(m_World.boundingBox()));

   // Replace GLC_Box default material
   GLC_Material* pRedMaterial= new GLC_Material(Qt::red);
   pRedMaterial->setOpacity(0.5);
   box.geomAt(0)->replaceMasterMaterial(pRedMaterial);

   // Add the box to the collection
   m_ViewCollection.add(box);
}

And the rendering method :
Code:
void GLWidget::paintGL()
{
   // Clear screen
   glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

   // Load identity matrix
   GLC_Context::current()->glcLoadIdentity();

   // Calculate camera depth of view
   m_GlView.setDistMinAndMax(m_World.boundingBox());

   // define the light
   m_Light.glExecute();

   // define view matrix
   m_GlView.glExecuteCam();

   // Render the scene
   m_World.render(0, glc::ShadingFlag);
   m_World.render(0, glc::TransparentRenderFlag);

   // Render the collection which contains the box
   m_ViewCollection.render(0, glc::WireRenderFlag); // To see box edged
   m_ViewCollection.render(0, glc::TransparentRenderFlag); // To Render transparent faces

   // Display UI Info (orbit circle)
   m_MoverController.drawActiveMoverRep();
}

It's should look like this :
Attachment:
bBoxView.jpg
bBoxView.jpg [ 28.55 KiB | Viewed 8753 times ]


@+


Fri Jun 29, 2012 1:11 pm
Profile

Joined: Mon Aug 16, 2010 7:55 am
Posts: 12
Post Re: How to create bounding box around object / mesh
Hi,
1. I load a Obj file into World
2. I create the box as you say
3. When I move my object with setMatrix and render the boundingbox again it change.

Appears as it work on absolute orientation and it not follow my obj file on his movement.

How can I obtain alwais the same boundingBox also if I set new position on my obj?

Thanks a lot again


Sat Nov 16, 2013 3:14 pm
Profile
Display posts from previous:  Sort by  
Reply to topic   [ 3 posts ] 

Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by STSoftware for PTF.