[osg-users] Switch between primitive and model

Ulrich Hertlein u.hertlein at sandbox.de
Mon Nov 12 13:01:42 PST 2018

Hi Charlie,

On 12/11/18 03:26, Charlie Tan wrote:
> 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,

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 488 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openscenegraph.org/pipermail/osg-users-openscenegraph.org/attachments/20181112/2489cc11/attachment.sig>

More information about the osg-users mailing list