Re: [osg-users] Matrix multiplication order

2018-03-22 Thread Florian GOLESTIN
Hi Robert,

Thanks for the answer, I understand now.

I worked as a Support Engineer and understand the hard choice of breaking an 
API :)

Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73149#73149





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Matrix multiplication order

2018-03-22 Thread Florian GOLESTIN
Hi everyone !

I don't get why in GLSL you transform a vertex like this:


Code:
vec4 result = matrix * vertex;



While in OSG I have to do it in the reverse order :


Code:
osg::Vec4 result = vertex * matrix;



Is it due to the Matrices major mode that are different from OpenGL and 
OpenSceneGraph ?

Thanks for demystifying me!

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=73145#73145





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [3rdparty] ImGui integration

2017-12-18 Thread Florian GOLESTIN
Hi Everyone,

I was thinking to integrate ImGUI with the non FPP version but I'm not sure how 
to do it.

Itself, ImGUI render the ui inside a vector of (vector of ) struct containing 
the triplet Vertex Position, UV coordinates and Color value. As it's and 
"immediate GU", It refresh and refill the buffers every frames.

Here, I see two solution:
 - Non-OSG'ish: render the UI still using the GL function (glGen...) and shader
 - OSG version using geometries (created and destructed each frame)

What would be the recommended solution to integrate such library?


Thank you!
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72599#72599





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Collada Importer with Blender

2017-12-01 Thread Florian GOLESTIN
Hello everyone, 

I've built OSG 3.5.7 with the Collada Plugin, however when I try to import a 
.dae file exported by Blender it fails with the following message:

Code:

$ bin/osgconvd ~/Téléchargements/BLEND/Player2.dae Player2.osgt
I/O error : Is a directory
Error: Extra content at the end of the document

Error: Error parsing XML in daeLIBXMLPlugin::read

Error: Failed to load file:/home/florian/jeux/OpenSceneGraph/build.gl2/

Load failed in COLLADA DOM
Load failed in COLLADA DOM conversion
Error reading file /home/florian/Téléchargements/BLEND/Player2.dae: read error
Error no data loaded.




Does it sounds familiar to someone?

Thanks,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72507#72507





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Displaying the normals of your models

2017-12-01 Thread Florian GOLESTIN
Thanks!

I forgot about EmitVertex. It's a nice solution!

Cheers,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72506#72506





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Displaying the normals of your models

2017-12-01 Thread Florian GOLESTIN
Hi everyone,

I have to debug a normal issue with my model, so I made a code to display them 
(transform normals in a bunch of gl_lines and create a resulted geometry).

I share the gist in case it may help:
https://gist.github.com/fulezi/95a9ac319fd1cbeca1b18a4cde3986dc



Have a nice day,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72504#72504





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Unexpected different lightening

2017-12-01 Thread Florian GOLESTIN
Hi Tang, 

You should be right has the normals are incorrect anyway. 
I've maybe messed up my copy-past debug and have to dig it more.

Thanks for you answer :)

Cheers,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72503#72503





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Mouse position to object space

2017-11-23 Thread Florian GOLESTIN
Hi Hakan,

If you want to simply drag (or do other transformation to) an object you can 
use the Dragger from the osgManipulator pluggin:


Code:

osgManipulator::TranslateAxisDragger




Otherwise you need to project the mouse to the world space.
If I recall correctly:



Code:

osgViewer::View *view = dynamic_cast(&actionAdapter);
const osg::Camera *camera = view->getCamera();

const osg::Matrixd viewMatrix = camera->getViewMatrix();
const osg::Matrix projectionMatrix = camera->getProjectionMatrix();
osg::Matrix inverseCameraMatrix;
inverseCameraMatrix.invert(viewMatrix * projectionMatrix);
osg::Vec3 worldPosition = osg::Vec3(ea.getXnormalized(), 
ea.getYnormalized(), 0.0f) *
inverseCameraMatrix;




The z value of the Vec3 is the Near Plane, set it to 1.0 to have the Far Plane 
projection.

Best,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72440#72440





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Unexpected different lightening

2017-11-22 Thread Florian GOLESTIN
Hi everyone, 

I've exported a blender scene with the osgexport module 
(https://github.com/cedricpinson/osgexport) however the lightening is not as 
bright as expected (see screenshot).

I've exported the same scene as wavefront (.obj) and it renders correctly.

Then I converted the .obj into a .osgt with osgcong to compare but I cannot 
spot the difference. I even copied the Material and Normal parts without 
success.

ScreenShot:

Code:

osgconv ../media/ZincTest.obj ../media/ZincTest.osgt 
osgviewer ../media/ZincTest.osgt ../media/islands.osgt




The bright green elements are the correct ones (from Wavefront)

What else I can look for?

Have a nice day!
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72437#72437




Attachments: 
http://forum.openscenegraph.org//files/capture_dcran_de_2017_11_22_16_54_33_649.png


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] [3rdparty] ImGui integration

2017-11-22 Thread Florian GOLESTIN
Thanks !

Yes Shader version is "in the pipe" :) 
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72436#72436





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] [3rdparty] ImGui integration

2017-11-09 Thread Florian GOLESTIN
Hi team,

I integrated DearImGui into OpenSceneGraph. 
I forked the Gist from Megaton. You can find my version here: 
https://gist.github.com/fulezi/d2442ca7626bf270226014501357042c.

Features:

Integrated with the OpenGL fixed pipeline
Works with ASCII char and special keys (Control, alt, Super, Shift, enter)
Partial integration of the UTF-8 keyboard (you can type 'ç' but not 'ê', it 
will result as '^e')
Referenced ImGuiCallBack

To Do:
Mouse scroll
(or not to do) Clipboard


Have a good day,
Florian[/url][/list]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=72343#72343




Attachments: 
http://forum.openscenegraph.org//files/capture_dcran_de_2017_11_09_11_49_48_118.png


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Solar system in OSG or OpenGL?

2017-01-07 Thread Florian GOLESTIN
Hi Chris,

Just my two cents:
As a beginner, when I started to use OSG, learning from the beginner guide and 
the net tutorials, I was quickly able to get a good rendering. 
However, due to my lack of knowledge in OpenGL, at some point I get stuck in m 
development. 

So I've decided to buy a book on OpenGL to learn it first then come back to OSG.

To summarize:
It's better to use OSG because a grand number of functionalities (and all the 
OpenGL boiler plate code) are already present, tested and used by others.
But I would suggest to first learn the basics of OpenGL.


I hope it helps.

Best,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=69911#69911





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiples scenes

2016-05-31 Thread Florian GOLESTIN
Hi Robert

I gave a look to the osg::Switch and it's interesting too!

I don't need to mix the two scenes, in addition I need to restore the position 
and the animation of the monsters. 
So I've opted for the "viewer.setSceneData(newModel);".
It works well so far!

Thanks for your answer!

Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67297#67297





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] clamp mouse cursor / position

2016-05-23 Thread Florian GOLESTIN
Hi Sebastian,

I'm not an expert, but in my case I've my own class overloading 
osgGA::StandardManipulator.
In this case, while overriding the method handleMouseMove I can call 
requestWarpPointer without recusiving call handleMouseMove.

Is it what you are looking for?

Best,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67214#67214





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Multiples scenes

2016-05-23 Thread Florian GOLESTIN
Hi Robert,

The player just move to a new scene so the previous one can be discarded.

By scene I wanted to mean the "root" node and all its children, and the 
callback, keeping only the view and the camera manipulator.
In the application, the player walk along a maze (an interior scene) and when 
he hits a door, he's "teleported" into another level of the maze so I load a 
new map with new walls and monsters...

Have a good day!

Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67213#67213





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Multiples scenes

2016-05-22 Thread Florian GOLESTIN
Hi everyone

I'm looking for the method to go from a scene to another one.
I've found that setting a new model scene works but is it the preferred way?

Code:

/* Changing the scene on the fly in a osg::NodeCallback */
viewer.setSceneData(scene2);





Thanks,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67193#67193





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using multiples texture for a geometry

2016-05-13 Thread Florian GOLESTIN
Hi Björn,

Texture Atlas! That was what I've in mind, I though I could use multiples image 
files. 

This feeling when you worked hard on a subject and now it become clear! :) 

Thank you all for your help!

Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67100#67100





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using multiples texture for a geometry

2016-05-09 Thread Florian GOLESTIN
Hi Robert, hi Sebastian,

Thanks for your help so far Robert, I hope you have a good trip in Germany!

Sebastian, thanks for your help, I understand what you mean. Because I used 0's 
for my texture mapping I was binding "void". That's why it appeared black.

On your example, I got the two textures mixed (blended). It seems to be the 
expected result from what I understand of the code. 

So my conclusion is, using multiples texture does not work as I expected! :)  
Actually I over-complicated the things.

I wanted to have multiples different textures not mixed (or blended) on a same 
geometry such as doing floor tiles 
(https://en.wikipedia.org/wiki/Porcelain_tile#/media/File:Chinese_porcelain_tiles,_Cochin_synagogue.jpg).
 But with this method, this is not possible to have one texture on a side and 
another texture on another side. Am I right?

So I ended up with using one geometry per texture and it worked as expected. 


Thanks for your patience!

Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67062#67062





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using multiples texture for a geometry

2016-05-06 Thread Florian GOLESTIN
Hi Robert,

I followed your suggestion and indeed the exported scenes seem different but I 
don't get this difference.

Please see in attachment for the source code and the exported scenes.

This source code create one drawable with two faces and two TextCoords buffers. 
The result is the same: if I apply the two texture it's dark. If I apply only 
one texture (either on the left or the right side) the unique texture is 
displayed correctly.

I've compared the .osgt scenes.
So there is obviously two 

Code:

Data 1 {
GL_TEXTURE_2D ON 
}




and two 

Code:

Data 1 {
osg::Texture2D {
UniqueID 4 
}
Value OFF 
}



Only one has a reference to the image but I think this is explained because the 
both have the same UniqueID.

And two

Code:

osg::Vec2Array {
UniqueID 11 
Binding BIND_PER_VERTEX 
vector 8 {
0 0 
0 0 
0 0 
0 0 
0 0 
0 1 
1 1 
1 0 
}
}



With different Textcoord as expected (this second part correspond to my right 
part).

I also tried to create two textures but no more chance.

I'm continuing investigating but I'm kind of stuck

Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67054#67054




Attachments: 
http://forum.openscenegraph.org//files/two_textures_115.osg
http://forum.openscenegraph.org//files/one_texture_359.osg
http://forum.openscenegraph.org//files/main_415.cpp


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using multiples texture for a geometry

2016-05-04 Thread Florian GOLESTIN
Hi Robert,

I tried without the SmoothingVisitor but it does not change anything.


However during my tests today I put a "Axes" object (the axes.osgt model from 
the OpenSceneGraph examples) and some part of the texture on the block below 
the object just appeared but really dark.
So it it make me think that it's not a texture problem but maybe a light 
problem.

I've tried then to use a full ambiant light:

Code:

osg::ref_ptr createLightSource( unsigned int num,
  const osg::Vec3& trans,
  const osg::Vec4& color )
{
  osg::ref_ptr light = new osg::Light;
  light->setLightNum( num );
  light->setDiffuse( color );

  /* full scene lightened: */
  light->setAmbient(osg::Vec4(1.0,1.0,1.0,1.0));
  light->setSpecular(osg::Vec4(1,1,1,1));  // some examples don't have this one

  
  light->setPosition( osg::Vec4(0.0f, 0.0f, 0.0f, 1.0f) );
  osg::ref_ptr lightSource = new
osg::LightSource;
  lightSource->setLight( light );
  osg::ref_ptr sourceTrans = new osg::MatrixTransform;
  sourceTrans->setMatrix( osg::Matrix::translate(trans) );
  sourceTrans->addChild( lightSource.get() );
  return sourceTrans;
}

int main(int argc, char **argv)
{
  osg::ArgumentParser arguments(&argc,argv);
  
  osg::ref_ptr root = new osg::Group;

  root->addChild(createLightSource(0, osg::Vec3(0, -2.0, 0), osg::Vec4(1.0, 
1.0, 1.0, 1.0)));
  root->addChild(createLightSource(1, osg::Vec3(0, -16.0, 10.0), osg::Vec4(1.0, 
1.0, 1.0, 1.0)));

  root->getOrCreateStateSet()->setMode( GL_LIGHT0, osg::StateAttribute::ON );
  root->getOrCreateStateSet()->setMode( GL_LIGHT1, osg::StateAttribute::ON );





Now the texture appears but are really dark such as there is no light.

Is it something related to states and inheritance?

Thanks,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67051#67051





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Using multiples texture for a geometry

2016-05-03 Thread Florian GOLESTIN
Hi Robert,

Sorry my mistake, I wanted to put only the interesting part but this is not 
efficient.
No more censure!


Code:

namespace Soleil
{

  LevelReader::LevelReader()
  {
//supportsExtension("level", "Text map format for Donjon");
  }

  LevelReader::~LevelReader()
  {
  }


  osg::ref_ptr  LevelReader::readFile(const std::string &file) const
  {
std::string fileName = osgDB::findDataFile(file);
if (fileName.empty()) return nullptr; // TODO throw e?

errno = 0;
std::cout << "Stream: " << fileName.c_str() << "\n";
std::ifstream stream;
stream.exceptions(std::ifstream::failbit); //  | std::ifstream::badbit
stream.open(fileName.c_str(), std::ios::in);
if (!stream) return nullptr; // TODO throw e

return readStream(stream);
  }
  
  osg::ref_ptr LevelReader::readStream(std::istream &stream) const
  {
charblock;  // current reading block
float   x = 0;  // Current position on x
float   y = 0;  // Current position on y
int wallCount = 0;  // Number of cubes
float   maxX = 0;   // Max size of the map in X


osg::ref_ptr level = new Soleil::Level();
std::string line;
while(std::getline(stream, line))
  {
std::stringstream linestream(line);

while (linestream >> block)
  {
/* TODO Configurable size for the blocks */
float posx = 1.0 * x; 
float posy = 1.0 * y; 
float endx = posx + 1.0;
float endy = posy + 1.0;

bool blockFound = false;
switch (block)
  {
  case '.':
break;
  case 'D':
level->_startingPosition = osg::Vec3(posx + .5, posy + .5, .3);
blockFound = true;
break;
  case 'd':
level->_startingOrientation = osg::Vec3(posx + .5, posy + .5, 
.3);
blockFound = true;
break;
  case 'x':
if (wallCount % 2)
  {
std::cout << "1" << "\n";
createCube(level.get(), *level->texcoords, 
*level->texcoords2, posx, posy, endx, endy);
  }
else
  {
std::cout << "2" << "\n";
createCube(level.get(), *level->texcoords2, 
*level->texcoords, posx, posy, endx, endy);
  }
blockFound = true;
wallCount++;
break;
// default:
//  blockFound = levelConfiguration(block);
//  break;
  }
if (blockFound == false)
  std::cout << "Unexpected character: " <<  block << std::endl;

x += 1.0;
maxX = std::max(x, maxX);
  }
x  = 0;
y -= 1.0; // TODO Cube size
  }
// TODO read failed?

// Floor -
level->vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
level->vertices->push_back(osg::Vec3(maxX, 0.0f, 0.0f));
level->vertices->push_back(osg::Vec3(maxX, y, 0.0f));
level->vertices->push_back(osg::Vec3(0, y, 0.0f));

level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
level->normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));

level->texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); // 0
level->texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); // 1
level->texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); // 2
level->texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); // 3

  
osg::ref_ptr geom = new osg::Geometry;
geom->setVertexArray(level->vertices);
geom->setNormalArray(level->normals, osg::Array::Binding::BIND_PER_VERTEX);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 24*wallCount+4)); // 
+4 for the floor texture coordinates
osgUtil::SmoothingVisitor::smooth(*geom);
//

// 
osg::ref_ptr geode = new osg::Geode;
geode->addDrawable(geom);


/* I added this in the hope to have the second texture appearing */
// osg::Material* material = new osg::Material;
// material->setColorMode(osg::Material::AMBIENT_AND_DIFFUSE);
// material->setAmbient(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 
1));
// material->setDiffuse(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 
1));
// material->setSpecular(osg::Material::FRONT_AND_BACK, osg::Vec4(1, 1, 1, 
1));
// material->setShininess(osg::Material::FRONT_AND_BACK, 64.0f);
// 
level->getOrCreateStateSet()->setAttribute(material,osg::StateAttribute::ON | 
osg::StateAttribute::OVERRIDE);



level->addChild(geode);


// Texture 1
geom->setTexCoordArray(0, level->texcoords.get());
{
  osg::ref_ptr texture = new osg::

Re: [osg-users] Using multiples texture for a geometry

2016-05-02 Thread Florian GOLESTIN
Hi Robert,

Thanks for your response!

I might have the two vectors for the textures coordinate.
Basically my idea is to have cubes to draw Labyrinth.
I read a file such as:

Code:

x
x.x
x



Where 'x' represents a wall.

I've a class named Level that hold two Vec2Array for the two textures, it also 
hold vertices and normals.
What I do is
 - Even: the first vector is filled with texture coordinates while the second 
is filled with 0
 - Odd: then the second time the first vector is filled with 0 and the second 
with texture coordinates.

Here is the code:

Code:

float   x = 0;
float   y = 0;
int wallCount = 0;

while(std::getline(stream, line))
  {
std::stringstream linestream(line);

while (linestream >> block)
  {
float posx = 1.0 * x; 
float posy = 1.0 * y; 
float endx = posx + 1.0;
float endy = posy + 1.0;
switch (block)
  {
  case 'x':
if (wallCount % 2) // Odd or Even?
createCube(level.get(), *level->texcoords, 
*level->texcoords2, posx, posy, endx, endy);
else
createCube(level.get(), *level->texcoords2, 
*level->texcoords, posx, posy, endx, endy);
wallCount++;
break;
x += 1.0;
  }
x  = 0;
y -= 1.0; /* We decrements y To keep the labyrinth as on the file */
  }


osg::ref_ptr geom = new osg::Geometry;
geom->setVertexArray(level->vertices);
geom->setNormalArray(level->normals, osg::Array::Binding::BIND_PER_VERTEX);
geom->addPrimitiveSet(new osg::DrawArrays(GL_QUADS, 0, 24*wallCount));
osgUtil::SmoothingVisitor::smooth(*geom);



  /*
   * @param Level   the container of the vertices, normals and textures for 
the walls of our labyrinth
   * @param tex the Vector that should receive the coordinate for the 
textures
   * @param skipthe second vector for texture filled with '0' to 'skip' 
this wall
   */
  void LevelReader::createCube(Soleil::Level *level, osg::Vec2Array &tex, 
osg::Vec2Array &skip,
  float posx, float posy, float endx, float endy) const
{
// -- Front
level->vertices->push_back(osg::Vec3(posx, posy, 0.0f));
level->vertices->push_back(osg::Vec3(endx, posy, 0.0f));
level->vertices->push_back(osg::Vec3(endx, posy, 1.0f));
level->vertices->push_back(osg::Vec3(posx, posy, 1.0f));

level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
level->normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));

tex.push_back( osg::Vec2(0.0f, 0.0f)); 
tex.push_back( osg::Vec2(0.0f, 1.0f)); 
tex.push_back( osg::Vec2(1.0f, 1.0f)); 
tex.push_back( osg::Vec2(1.0f, 0.0f)); 
//
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
  
  
// -- top
level->vertices->push_back(osg::Vec3(posx, posy, 1.0f));
level->vertices->push_back(osg::Vec3(endx, posy, 1.0f));
level->vertices->push_back(osg::Vec3(endx, endy, 1.0f));
level->vertices->push_back(osg::Vec3(posx, endy, 1.0f));

level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
level->normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));

tex.push_back( osg::Vec2(0.0f, 0.0f)); 
tex.push_back( osg::Vec2(0.0f, 1.0f)); 
tex.push_back( osg::Vec2(1.0f, 1.0f)); 
tex.push_back( osg::Vec2(1.0f, 0.0f)); 
//
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
  
  
// -- back
level->vertices->push_back(osg::Vec3(posx, endy, 0.0f));
level->vertices->push_back(osg::Vec3(endx, endy, 0.0f));
level->vertices->push_back(osg::Vec3(endx, endy, 1.0f));
level->vertices->push_back(osg::Vec3(posx, endy, 1.0f));

level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
level->normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));

tex.push_back( osg::Vec2(0.0f, 0.0f)); 
tex.push_back( osg::Vec2(0.0f, 1.0f)); 
tex.push_back( osg::Vec2(1.0f, 1.0f)); 
tex.push_back( osg::Vec2(1.0f, 0.0f)); 
  //
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 
skip.push_back( osg::Vec2(0.0f, 0.0f)); 

  
// -- Bottom
level->vertices->push_back(osg::Vec3(posx, posy, 0.0f));
level->vertices->push_back(osg::Vec3(endx, posy, 0.0f));
 

[osg-users] Using multiples texture for a geometry

2016-05-01 Thread Florian GOLESTIN
Hi everyone,

I've a Geometry (which is a wall) and I want to put two textures on it. A part 
with a first texture and a second part with a  second texture. 

I wrote the code above :

Code:

//Texture 1
geom->setTexCoordArray(0, level->texcoords.get());
{
  osg::ref_ptr texture = new osg::Texture2D;
  osg::ref_ptr image = 
osgDB::readImageFile("media/textures/stone_3_2048x2048.jpg");
  texture->setImage(image);
  texture->setUnRefImageDataAfterApply(true);
  level->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture);
}
//Texture 2
geom->setTexCoordArray(1, level->texcoords2.get());
{
  osg::ref_ptr texture = new osg::Texture2D;
  osg::ref_ptr image = 
osgDB::readImageFile("media/textures/Metal_seamless2_ch16.jpg");
  texture->setImage(image);
  texture->setUnRefImageDataAfterApply(true);
  level->getOrCreateStateSet()->setTextureAttributeAndModes(1, texture);
}




However the wall appears completely black (no textures).

If I comment the "Texture 2" block, the part of the wall with the first texture 
is displayed correctly. And if I comment the "Texture 1" block the part of the 
wall with the second texture is displayed correctly.

I am missing something?

Thank you,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=67039#67039





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


[osg-users] Create a custom StandardManipulator

2016-04-23 Thread Florian GOLESTIN
Hi everyone,

I'm trying to develop my own Camera Manipulator (in order to have a Doom-like 
view). I've looked at documentations but there are still questions for me.

First question I had was "How to translate an object relatively to its own 
position (and not to the world)". I'm still looking for a way doing this with 
Matrix, however, I've found a solution with quaternion :
You can multiply a Quaternion with a Vector to move relatively to the 
direction. 

For instance: 

Code:

_position += _attitude * translation;



where 

"_position" is a Vec3 representing the current position (e.g. from 
osg::PositionAttitudeTransform)
"_attitude" is a quaternion representing the current direction (e.g. from 
osg::PositionAttitudeTransform)
"translation" is the relative translation (as Vec3) to apply


This solution provides me good result but is it a good way?



Then I wanted to create the camera manipulator, so I've extended the class such 
as:

Header

Code:

class FirstPersonManipulator : public osgGA::StandardManipulator, public 
osg::PositionAttitudeTransform




Source

Code:

FirstPersonManipulator::FirstPersonManipulator(const osg::Vec3d &eye, const 
osg::Vec3d ¢er)
{
  osg::Vec3 up(0.0, 0.0, 1.0);

  setTransformation(eye, center, up);

  _homeEye = eye;
  _homeCenter = center;
  _homeUp = up;
  _autoComputeHomePosition = false;
}
  
FirstPersonManipulator::~FirstPersonManipulator(void)
{
}

void  FirstPersonManipulator::setTransformation(const osg::Vec3d &eye, const 
osg::Quat &rotation)
{

  std::cout << "FirstPersonManipulator::setTransformation: Old Position [" << 
_position << " X " << _attitude
 << "] New Position: [" <<  eye << " X " << rotation << "]\n";
  this->_position = eye;
  this->_attitude = rotation;
}

void  FirstPersonManipulator::setTransformation(const osg::Vec3d &eye, const 
osg::Vec3d ¢er, const osg::Vec3d &up)
{
  osg::Matrixd view;

  view.makeLookAt(eye, center, up);

  /* This line is required otherwise the canera seems "head-down" */
  view.makeRotate(osg::DegreesToRadians(90.0), osg::Vec3(1, 0, 0));


  std::cout << "FirstPersonManipulator::setTransformation: " << view  << "\n";

  this->setTransformation(eye, view.getRotate());
}

void  FirstPersonManipulator::getTransformation(osg::Vec3d &eye, osg::Quat 
&rotation) const
{
  eye = this->_position;
  rotation = this->_attitude;
}

void  FirstPersonManipulator::getTransformation(osg::Vec3d &eye, osg::Vec3d 
¢er, osg::Vec3d &up) const
{
  osg::Matrixd view;

  view.setTrans(this->_position);
  view.setRotate(this->_attitude);
  view.getLookAt(eye, center, up);
}

void  FirstPersonManipulator::setByMatrix(const osg::Matrixd &matrix)
{
  std::cout << "FirstPersonManipulator::setByMatrix: " << matrix << "\n";
  this->setTransformation(matrix.getTrans(), matrix.getRotate());
}
  
void  FirstPersonManipulator::setByInverseMatrix(const osg::Matrixd &matrix)
{
  std::cout << "FirstPersonManipulator::setByInverseMatrix: " << matrix << "\n";
  setByMatrix(osg::Matrixd::inverse(matrix));
}

osg::Matrixd  FirstPersonManipulator::getMatrix() const
{
  osg::Matrixd view;

  view.setTrans(this->_position);
  view.setRotate(this->_attitude);
  std::cout << "FirstPersonManipulator::getMatrix: " << view << "\n";
  return view;
}
  
osg::Matrixd  FirstPersonManipulator::getInverseMatrix() const
{
  std::cout << "FirstPersonManipulator::getInverseMatrix: " << 
osg::Matrixd::inverse(getMatrix()) << "\n";
  return osg::Matrixd::inverse(getMatrix());
}




Here the camera is correctly positioned and oriented but I had to add this line 
(in FirstPersonManipulator::setTransformation):

Code:

  /* This line is required otherwise the canera seems "head-down" */
  view.makeRotate(osg::DegreesToRadians(90.0), osg::Vec3(1, 0, 0));



Otherwise the camera seemed to had foot up and head down.

Is the code above correct?
Do you have an idea about the rotation I had to do?


(PS: Sorry I cannot get rid of the 'question-mark '?' - I've replaced all tab 
and spaces but they still appears)

Thanks,
Florian[/list]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66937#66937





___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org


Re: [osg-users] Drawing a textured cube

2016-04-11 Thread Florian GOLESTIN
Hi Christian,

Thanks for your answer.

Indeed using 4 faces solved the situation, now I've a cube fully textured. I've 
also change from triangles to quads. I don't know if I've eared anything.


I add the code below (it may help someone else).

Code:

osg::ref_ptr vertices = new osg::Vec3Array;
osg::ref_ptr texcoords = new osg::Vec2Array();
osg::ref_ptr normals = new osg::Vec3Array;

// -- top
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 1.0f));
vertices->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));

normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));
normals->push_back(osg::Vec3(0.0f,-1.0f, 0.0f));

texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); 
texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); 


// -- top
vertices->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 1.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 1.0f));
vertices->push_back(osg::Vec3(0.0f, 1.0f, 1.0f));

normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));
normals->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));

texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); 
texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); 


// -- back
vertices->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 1.0f));
vertices->push_back(osg::Vec3(0.0f, 1.0f, 1.0f));

normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
normals->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));

texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); 
texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); 


// -- Bottom
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 0.0f));
vertices->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));

normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));
normals->push_back(osg::Vec3(0.0f, 0.0f, -1.0f));

texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); 
texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); 


// -- Left
vertices->push_back(osg::Vec3(0.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(0.0f, 1.0f, 0.0f));
vertices->push_back(osg::Vec3(0.0f, 1.0f, 1.0f));
vertices->push_back(osg::Vec3(0.0f, 0.0f, 1.0f));

normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));
normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));
normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));
normals->push_back(osg::Vec3(-1.0f, 0.0f, 0.0f));

texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); 
texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); 


// -- Right
vertices->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 0.0f));
vertices->push_back(osg::Vec3(1.0f, 1.0f, 1.0f));
vertices->push_back(osg::Vec3(1.0f, 0.0f, 1.0f));

normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));
normals->push_back(osg::Vec3(1.0f, 0.0f, 0.0f));

texcoords->push_back( osg::Vec2(0.0f, 0.0f) ); 
texcoords->push_back( osg::Vec2(0.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 1.0f) ); 
texcoords->push_back( osg::Vec2(1.0f, 0.0f) ); 




osg::ref_ptr geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->setNormalArray(normals, osg::Array::Binding::BIND_PER_VERTEX);
geom->addPrimitiveSet( new osg::DrawArrays(GL_QUADS, 0, 24));
geom->setTexCoordArray(0, texcoords.get());
osgUtil::SmoothingVisitor::smooth(*geom);


geom->setTexCoordArray(0, texcoords.get(), 
osg::Array::Binding::BIND_PER_VERTEX);


osg::ref_ptr texture = new osg::Texture2D;
osg::ref_ptr image = 
osgDB::readImageFile("/usr/home/florian/Documents/Jeux/futur/stone_3_2048x2048.jpg");
texture->setImage(image);
texture->setUnRefImageDataAfterApply(true); 





Best,
Florian

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66787#66787




Attachments: 
http://forum.openscenegraph.org//files/screenshot_from_2016_04_11_21_25_21_100.png


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.opensceneg

[osg-users] Drawing a textured cube

2016-04-10 Thread Florian GOLESTIN
Hi everyone,

I'm learning OSG with the quick start guide and the example but I'm struggling 
drawing a textured cube. The shape is correct but only 4 faces are textured on 
6.


Below is the shape:


Code:

osg::ref_ptr vertices = new osg::Vec3Array(8);

(*vertices)[0].set( 0.0f, 0.0f, 0.0f);
(*vertices)[1].set( 1.0f, 0.0f, 0.0f);
(*vertices)[2].set( 1.0f, 0.0f, 1.0f);
(*vertices)[3].set( 0.0f, 0.0f, 1.0f);
(*vertices)[4].set( 0.0f, 1.0f, 1.0f);
(*vertices)[5].set( 1.0f, 1.0f, 1.0f);
(*vertices)[6].set( 1.0f, 1.0f, 0.0f);
(*vertices)[7].set( 0.0f, 1.0f, 0.0f);



osg::ref_ptr indices = new 
osg::DrawElementsUInt(GL_TRIANGLES);
// Front
indices->push_back( 0 ); indices->push_back( 1 ); indices->push_back( 2 );
indices->push_back( 3 ); indices->push_back( 0 ); indices->push_back( 2 );
// Top
indices->push_back( 3 ); indices->push_back( 4 ); indices->push_back( 2 );
indices->push_back( 4 ); indices->push_back( 5 ); indices->push_back( 2 );
// Back
indices->push_back( 6 ); indices->push_back( 7 ); indices->push_back( 5 );
indices->push_back( 4 ); indices->push_back( 7 ); indices->push_back( 5 );
// left ---
indices->push_back( 7 ); indices->push_back( 3 ); indices->push_back( 4 );
indices->push_back( 0 ); indices->push_back( 7 ); indices->push_back( 3 );
// right
indices->push_back( 2 ); indices->push_back( 5 ); indices->push_back( 6 );
indices->push_back( 1 ); indices->push_back( 2 ); indices->push_back( 6 );
// Bottom
indices->push_back( 0 ); indices->push_back( 7 ); indices->push_back( 1 );
indices->push_back( 1 ); indices->push_back( 6 ); indices->push_back( 7 );


osg::ref_ptr geom = new osg::Geometry;
geom->setVertexArray(vertices);
geom->addPrimitiveSet(indices);
osgUtil::SmoothingVisitor::smooth(*geom);




I've a first question here: Do the indice order has an importance?

For instance first line could also be:

Code:
indices->push_back( 2 ); indices->push_back( 1 ); indices->push_back( 0 );




Then the texture:


Code:

osg::ref_ptr texcoords = new osg::Vec2Array(16);
(*texcoords)[0].set( osg::Vec2(0.0f, 0.0f) );
(*texcoords)[1].set( osg::Vec2(0.0f, 1.0f) );
(*texcoords)[2].set( osg::Vec2(1.0f, 1.0f) );
(*texcoords)[3].set( osg::Vec2(1.0f, 0.0f) );
//
(*texcoords)[4].set( osg::Vec2(0.0f, 0.0f) );
(*texcoords)[5].set( osg::Vec2(0.0f, 1.0f) );
(*texcoords)[6].set( osg::Vec2(1.0f, 1.0f) );
(*texcoords)[7].set( osg::Vec2(1.0f, 0.0f) );

geom->setTexCoordArray(0, texcoords.get());

osg::ref_ptr texture = new osg::Texture2D;
osg::ref_ptr image = osgDB::readImageFile("stone_3_2048x2048.jpg");
texture->setImage(image);
texture->setUnRefImageDataAfterApply(true);
texture->setDataVariance(osg::Object::DYNAMIC);

node->addDrawable(geom);
node->getOrCreateStateSet()->setTextureAttributeAndModes(0, texture);





Here I'm not sure to understand the 'textcoords' array. At the beginning I 
thought it was the location on the image, but with only 4 parameters, the cube 
was textured on the front and half of the top face.
Doubling the texture brought texture on 4 (front, top, back, bottom) 6 faces .



Do you have any suggestion or documentation I can look for?


Thank you!

Cheers,
Florian[/img]

--
Read this topic online here:
http://forum.openscenegraph.org/viewtopic.php?p=66771#66771




Attachments: 
http://forum.openscenegraph.org//files/screenshot_from_2016_04_08_22_21_22_108.png


___
osg-users mailing list
osg-users@lists.openscenegraph.org
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org