OpenSceneGraph Forum Forum Index OpenSceneGraph Forum
Official forum which mirrors the existent OSG mailing lists. Messages posted here are forwarded to the mailing list and vice versa.
 
   FAQFAQ    SearchSearch    MemberlistMemberlist    RulesRules    UsergroupsUsergroups    RegisterRegister 
 Mail2Forum SettingsMail2Forum Settings  ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
   AlbumAlbum  OpenSceneGraph IRC ChatOpenSceneGraph IRC Chat   SmartFeedSmartFeed 

Switch between primitive and model


 
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General
View previous topic :: View next topic  
Author Message
charlietan789
Newbie


Joined: 07 Nov 2018
Posts: 5

PostPosted: Mon Nov 12, 2018 2:25 am    Post subject:
Switch between primitive and model
Reply with quote

Hi,

I am trying to toggle between a model that I have loaded (a unit cube) and a colored surface (a unit triangle). Thus, the triangle rendered should be half the area of the unit cube's face. In addition, the triangle rendered should lie on the cube face itself.

// Model
auto loadedModel = readRefNodeFiles(...);
auto swtch = new Switch();

scene->addChild(swtch);
swtch->addChild(loadedModel); //swtch[0]


// Colored surface
Node* geode;
auto polyGeom = Geometry();
polyGeom->setVertexArray(...); //Set to (0,0,0), (1,0,0), (1,1,0)
polyGeom->setColorArray(...);
polyGeom->setNormalArray(...);
geode->addDrawable(polyGeom);

swtch->addChild(geode); //swtch[1]


However, when I toggle between:
swtch->setSingleChildOn(0);
and
swtch->setSingleChildOn(1);

The size, position and the orientation of the colored surface is way off as compared to my cube model.

Initially I thought it has something to do with my transformation matrix not being in the global frame, so I did this:

auto nodePath = scene->getChild(0)->asGroup()->getChild(0)->getParentalNodePaths()[0];
auto matrix = osg::computeLocalToWorld(nodePath);
auto trans1 = MatrixTransform;
trans1->setMatrix(matrix);
trans1->addChild(geode);

swtch->addChild(trans1);

But it did not work too. Any help is much appreciated!


Thank you!

Cheers,
Charlie
Back to top
View user's profile Send private message
Ulrich Hertlein
Guest





PostPosted: Mon Nov 12, 2018 9:02 pm    Post subject:
Switch between primitive and model
Reply with quote

Hi Charlie,

On 12/11/18 03:26, Charlie Tan wrote:
Quote:
I am trying to toggle between a model that I have loaded (a unit cube) and a colored surface (a unit triangle). Thus, the triangle rendered should be half the area of the unit cube's face. In addition, the triangle rendered should lie on the cube face itself.

// Model
auto loadedModel = readRefNodeFiles(...);
auto swtch = new Switch();

scene->addChild(swtch);
swtch->addChild(loadedModel); //swtch[0]

// Colored surface
Node* geode;
auto polyGeom = Geometry();
polyGeom->setVertexArray(...); //Set to (0,0,0), (1,0,0), (1,1,0)
polyGeom->setColorArray(...);
polyGeom->setNormalArray(...);
geode->addDrawable(polyGeom);

swtch->addChild(geode); //swtch[1]
...
The size, position and the orientation of the colored surface is way off as compared to my cube model.

You didn't say much about how the unit cube is constructed, but usually it means that it
has an edge length of one (1.0) and is centered around the origin (0,0,0). This usually
also implies that the model matrix is the identity matrix.

So corners will be at min(-0.5, -0.5, -0.5) and max(0.5, 0.5, 0.5).

The triangle you are constructing, however, extends from the origin with an edge length of
1.0. Try to offset your triangle by translate(-0.5, -0.5, -0.5) and you should see it
lining up.

You can also use the coordinates directly, e.g. a triangle (-0.5, -0.5, -0.5), (0.5, -0.5,
-0.5), (0.5, 0.5, -0.5). Or something along those lines, depending on which face of the
cube you want to overlay.

Hope this helps,
Cheers,
/Ulrich




------------------
Post generated by Mail2Forum
Back to top
charlietan789
Newbie


Joined: 07 Nov 2018
Posts: 5

PostPosted: Thu Nov 15, 2018 7:24 am    Post subject:
Reply with quote

Hi,

Yep you are right. that was a silly mistake. thanks!

Thank you!

Cheers,
Charlie
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    OpenSceneGraph Forum Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
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 vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum

Similar Topics
Topic Author Forum Replies Posted
No new posts I have a question about the shading p... newlife958 General 0 Thu Oct 10, 2019 7:12 am View latest post
No new posts How do I move a Texture in an model ... newlife958 General 10 Tue Sep 17, 2019 1:16 am View latest post
No new posts Dragging individual model nodes arfaa General [forum] 9 Tue Apr 23, 2019 1:10 pm View latest post
No new posts Using switches to switch between diff... stc954 General 0 Sun Mar 17, 2019 6:40 pm View latest post
No new posts why does the adding of lighting shade... mirro General 0 Mon Feb 11, 2019 3:03 am View latest post


Board Security Anti Bot Question MOD - phpBB MOD against Spam Bots
Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP