Re: [osg-users] Decompose osg::Matrix and apply to osg::PositionAttitudeTransform

2009-10-15 Thread Andrew Thompson
Another slant at this, I've created a transform type to inherit osg::Transform 
that lets me set by matrix and by position, attitude, scale. 


Code:

class ExtendedTransform : public osg::Transform
{
public:

ExtendedTransform();

ExtendedTransform(const ExtendedTransform& tf,const 
osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
osg::Transform(tf,copyop),
m_matrixTransform(tf.m_matrixTransform)
{
}


META_Node(osg, ExtendedTransform);

inline void setPosition(const osg::Vec3f& pos) 
{ 
m_matrixTransform.setTrans(pos);
dirtyBound(); 
}
inline const osg::Vec3f& getPosition() const 
{ 
return m_matrixTransform.getTrans(); 
}

inline void setAttitude(const osg::Quat& quat) 
{ 
m_matrixTransform.setRotate(quat);
dirtyBound(); 
}
inline const osg::Quat& getAttitude() const 
{ 
return m_matrixTransform.getRotate(); 
}

inline void setScale(const osg::Vec3f& scale) 
{ 
osg::Vec3d tr = m_matrixTransform.getTrans();
osg::Quat rt = m_matrixTransform.getRotate();
m_matrixTransform.makeIdentity();
m_matrixTransform.preMultTranslate(tr);
m_matrixTransform.preMultRotate(rt);
m_matrixTransform.preMultScale(scale);
dirtyBound(); 
}
inline const osg::Vec3f& getScale() const 
{ 
return m_matrixTransform.getScale(); 
}   

inline const osg::Matrix & getMatrix() const
{
return m_matrixTransform;
}

inline void setMatrix(const osg::Matrix & matrix)
{
m_matrixTransform.set(matrix);
}

virtual bool computeLocalToWorldMatrix(osg::Matrix& 
matrix, osg::NodeVisitor* nv) const;
virtual bool computeWorldToLocalMatrix(osg::Matrix& 
matrix, osg::NodeVisitor* nv) const;


protected :

virtual ~ExtendedTransform() {}

osg::Matrixf m_matrixTransform;
};




As you can see the get/set position, scale, rotation methods are pretty 
inefficient, however I won't actually be calling these very often (Usually from 
a textbox in the UI to directly manipulate the object). 

The implementation of computeLocalToWorldMatrix and computeWorldToLocalMatrix 
is similar to that in MatrixTransform.cpp in the OSG source. 

I also don't store an internal inverse matrix (Its computed on the fly). This 
is to keep the memory requirements for my ExtendedTransform down as I'm using 
these everywhere. 

Any thoughts on the above method to solve my problem? 

thank you for your time, 
Andrew

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





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


[osg-users] Decompose osg::Matrix and apply to osg::PositionAttitudeTransform

2009-10-15 Thread Andrew Thompson
Hi there, 

This might be a load of rubbish and not possible mathematically, but I'm trying 
to decompose a matrix and apply it to an osg::PositionAttitudeTransform in 
order to set the PAT by matrix. 

The reasoning behind this is I am using PAT to give a human friendly position, 
rotation, scale for objects in a CAD-style application, but in certain 
circumstances, I would like to apply a matrix directly to the PAT and say 
"That's your matrix, use that". 

I have tried this


Code:

osg::Vec3 position = matrix.getTrans();
osg::Vec3 scale = matrix.getScale();
osg::Quat rotation = matrix.getRotate();

this->positionAttitude->setPosition(position);
this->positionAttitude->setScale(scale);
this->positionAttitude->setAttitude(rotation);




and it gives odd results. Also I was looking at matrix.decompose but I'm not 
sure what to do with "Scale Orientation". 

can anyone put me out of my matrix misery!?

Thank you!

Cheers,
Andrew

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





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


[osg-users] Screenshot of Current view at specific size using ScreenCaptureHandler

2009-10-12 Thread Andrew Thompson
Hi there, 

I'm using the ScreenCaptureHandler to capture a screenshot of the current view 
and save it to disk. I would ideally like to save at a specific resolution, say 
1280x1024, however the handler is saving the image at the current size of the 
viewer. 

My application is a CAD style application so is not full screen. the user is 
free to resize the window and that includes the viewer. Ideally I'd like 
screenshots to be taken at a fixed size and aspect ratio. 

Anyway here's my code. Can anyone suggest what I could do to adjust the 
screenshot size?

BTW - I tried setting the viewport size on the camera but this didn't result in 
a larger image, although it did result in the image appearing to be large 
enough to fit my target size (It was stretched).


Code:

// Create a screen capture handler to capture the screen to image
osg::ref_ptr capturedImage;
osg::ref_ptr screenCaptureHandler = new 
osgViewer::ScreenCaptureHandler(); 

// Create a CWriteToMemoryImageCaptureOperation to get the image out
// NOTE:
// All this does is let me get the image out in memory so I can save it
// What I will eventually do is convert it to .NET Bitmap to pass to 
// other parts of my application
osg::ref_ptr writeMem = new 
Native::CWriteToMemoryImageCaptureOperation();

// Set the capture operation on the screenCaptureHandler
screenCaptureHandler->setCaptureOperation(writeMem);

// Capture the next frame
// viewer is the osgviewer instance
screenCaptureHandler->captureNextFrame(*this->viewer);

// 
// Perform a Render Operation
//

// Get the default scene camera
osg::Camera * camera = this->viewer->getCamera();

// Update the camera view/projection matrices
camera->setProjectionMatrixAsPerspective(fieldOfView, aspect, nearClip, 
farClip);
camera->setViewMatrixAsLookAt(GetCameraPosition(), GetCameraTarget(), 
GetUpVector());

// Render the scene
this->viewer->frame();  

// Wait for the captured image to be filled
// NOTE: This really needs to be changed. An event should be raised by
// CWriteToMemoryImageCaptureOperation and passed out to calling code when 
// the image is ready 
while(!capturedImage.valid())
{
capturedImage = writeMem->GetImage();
}

// TEST:
// Write the image to file
bool success = osgDB::writeImageFile(*capturedImage, "C:\\Apps\\Test.bmp");










Thank you!

Cheers,
Andrew

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





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


[osg-users] Clarification on use of Manipulators in CAD-Style app

2009-09-25 Thread Andrew Thompson
Hi there, 

I am developing a CAD-Style application and am interested in using 
osgManipulator to provide picking, moving, rotating and scaling of objects. I 
just have a couple of questions with regard to the use of manipulators, and 
hope some of you can take the time to answer them for me. 

Firstly my application currently has a relatively flat scenegraph, where each 
"Object" in the CAD app is arranged as follows:


Code:

PositionAttitudeTransform
|
Geode
| 
Geometry




Then I have N "Objects" arranged as above in the scene that are a child of the 
root scene node (so a flat scene graph). 

>From my understanding from reading the osgManipulator example, to manipulate 
>an object I can use the following hierarchy:

[Image: 
http://i137.photobucket.com/albums/q217/andyb1979/manpulatorhierachy.png ]

In this diagram Geode is the object I want to manipulate, so I would replace 
that with the PAT from my "3D Object" implementation, Selection wraps the 
object to manipulate, Dragger can go anywhere in the scene and the 
CommandManager links the Dragger to the Selection. 

So -- some questions on how I may use this in my app:

* Firstly, to select an object, I pick it. At this point should I create a 
Selection and place in-between my 3D object and SceneRoot? Or can selection be 
anywhere and just place the object as a child of that?

* Secondly can the dragger be anywhere in the scene hierachy or must it be a 
parent of the selection?

* Similarly, does the Selection have to be specifically put between my 3D 
object and the scene root (In a CAD-Style app I will be selecting/deselecting 
objects quite regularly)

* Say my object has a transform applied to it by its 
PositionAttitudeTransform. I need to somehow get that transform, apply to the 
dragger, then let the user manipulate it and apply the resultant transform to 
the PAT, removing the dragger/selection from the scene. Any ideas how this 
could work?

* Is there a way to get an event or call-back out for each translate, rotate, 
scale operation as I need to push these into an undo-redo stack

* Finally, could the above be modified to work with multiple objects in the 
same selection and how would I apply the Dragger transform to all of them 
before/after the event? 



Thanks for your time, any insights would be gratefully received. 

Andrew[/list]

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





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


Re: [osg-users] Excluding a Geode from Small Feature Culling

2009-09-08 Thread Andrew Thompson
Hi there, and thanks for your response, 

well I am using small feature culling in my application to improve performance. 
Its a CAD-style app and I have hundreds of thousands of Geodes on the screen at 
any one time. Many are really small so I am throttling small-feature culling to 
maintain a decent framerate when moving around. When static the scene re-draws 
everything. 

But - there are certain objects, markers around the scene, I'd like to exclude 
from the small feature cull if possible. 

If its not possible, no matter, just was hoping there was a simple solution to 
this. 

Thank you, 
Andrew

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





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


[osg-users] Excluding a Geode from Small Feature Culling

2009-09-08 Thread Andrew Thompson
Hi there, 

a quick question for you guys, is it possible for a Geode to be excluded from 
SMALL_FEATURE_CULLING?


Thank you!

Andrew

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





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


[osg-users] Loading an osg::Image using setImage

2009-08-20 Thread Andrew Thompson
Hi there, 

I am trying to load an osg::Image using the setImage method - inparticular I am 
copying a Managed bitmap (System.Drawing.Bitmap) to the osg::Image to use it as 
a texture map. 

As you can see I'm having a few problems. Here's the osg::Image texture mapped 
onto a quad when I load it in from file using osgDB::readImageFile

[Image: http://i137.photobucket.com/albums/q217/andyb1979/tquadreadimage.png ]

Here's the same textured quad, but the osg::Image was created using setImage 
and a copy from a managed bitmap

[Image: http://i137.photobucket.com/albums/q217/andyb1979/th_tquadsetimage.png ]

As you can see the image seems to have been inverted and flipped!

Here is my code to convert a managed bitmap to osg::Image. The input bitmap has 
been loaded from file, is in the format 24bpp RGB. 

I know I'm getting the size/bits per pixel right as the output osg::Image is 
the right shape and size, with no tearing. However I don't know why the image 
is inverted!


Code:

osg::ref_ptr 
SceneUtil::ManagedBitmapToOSGImage(System::Drawing::Bitmap ^ bitmap)
{
//
// Check params
//

if (bitmap == nullptr)
{
throw gcnew Exception("Unable to convert 
System::Drawing::Bitmap to osg::Image as the input image is null");
}

if (bitmap->PixelFormat != 
System::Drawing::Imaging::PixelFormat::Format24bppRgb)
{
throw gcnew Exception("Unable to convert 
System::Drawing::Bitmap to osg::Image as the input image must be in the format 
Format24bppRgb");
}

// Create a new OSG Image
osg::ref_ptr image = new osg::Image();

System::Drawing::Imaging::BitmapData ^ bitmapData = bitmap->LockBits(
System::Drawing::Rectangle(0, 0, bitmap->Width, 
bitmap->Height), 
System::Drawing::Imaging::ImageLockMode::ReadOnly, 
System::Drawing::Imaging::PixelFormat::Format24bppRgb);

// Create data to hold the destination image
BYTE * ptrSrcImage = (BYTE*)bitmapData->Scan0.ToPointer();
BYTE * ptrDestImage = new unsigned char [bitmap->Width * bitmap->Height 
* 3];   
BYTE * ptrSourceRow = nullptr;
BYTE * ptrDestRow = nullptr;

int iWidth = bitmapData->Width;
int iHeight = bitmapData->Height;
int iStride = bitmapData->Stride;

// Copy the System::Drawing::Bitmap instance over line by line - this 
gets around the 
// lack of stride support in the osg::Image. 
for(int i = 0; i < iHeight; i++)
{
// Get the source row pointer
ptrSourceRow = ptrSrcImage + (i * iStride);

// Get the destination row pointer
ptrDestRow = ptrDestImage + (i * (iWidth * 3));

// Copy the source row to the destination row
memcpy(ptrDestRow, ptrSourceRow, iWidth * 3);
}

// Set the data on the osg::Image
image->setImage(
bitmap->Width, 
bitmap->Height, 
1, 
GL_RGB,
GL_RGB,
GL_UNSIGNED_BYTE, 
ptrDestImage, 
osg::Image::USE_NEW_DELETE);

bitmap->UnlockBits(bitmapData);

return image;
}




Any ideas?

Thank you!

Andrew

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





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


Re: [osg-users] transparent object sorting and back face culling

2009-08-18 Thread Andrew Thompson
Hi Paul, 

Cheers for your response, ok I missed that first time around, so it is 
possible, that's good, just not 100% sure on how you implemented it. 

One special case is in my system the transparent box is sort of a zone that the 
camera may move inside or outside. I need it to render properly in both cases. 
Also the box may be irregular (Imaging a polygon for top and bottom with 3-N 
points and a fixed height. Top/bottom polygons are the same shape).

So to clarify, should I:

1. Create each face (inner and outer) as well as top/bottom as individual 
Geodes, with one Geometry per Geode, one Quad per Geometry

2. Create a stateset on each geode, and set render bin details as follows:


Code:

// Where lower values are the inner faces, higher are outer
ss->setRenderBinDetails(1, "DepthSortedBin");
ss->setRenderBinDetails(2, "DepthSortedBin");
...
ss->setRenderBinDetails(10, "DepthSortedBin");
ss->setRenderBinDetails(11, "DepthSortedBin");




3. Then depending on whether the camera is inside or outside, swap the order of 
the inner/outer faces

4. Do the above in the Update pass

Does this sound about right?

Thank you!
Andrew

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





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


Re: [osg-users] transparent object sorting and back face culling

2009-08-17 Thread Andrew Thompson
Hi there

A quick related question for you guys, does OSG do the transparency bin sorting 
per Geode or per primitive?

I have a Geode with multiple transparent primitives in it, however one is a box 
with 4 sides created using QUAD_STRIP and top/bottom created using POLYGON and 
as such as not coming out quite right. 

[Image: http://i137.photobucket.com/albums/q217/andyb1979/TransCube.png ]

If I create individual QUAD's will this work better? Or perhaps does it have to 
be individual Geodes to get the sorting working right?

Thank you!

Andrew

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





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


Re: [osg-users] obtaining vertices

2009-08-13 Thread Andrew Thompson
Hi Brett

Could you elaborate on how you did it? I am facing a similar problem. 

Thank you!

Cheers,
Andrew

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





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


Re: [osg-users] Using OSGShadow to compute and return a shadow map in a texture or bitmap

2009-08-11 Thread Andrew Thompson
I realise this is a bit of a complicated question, but does anyone have any 
ideas if this is possible with OSG?

Cheers, 
Andrew

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





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


Re: [osg-users] Get the top coordonates from screen of an object

2009-08-11 Thread Andrew Thompson
Hi Adrien, 

I'm afraid I don't have an answer for you, but I am about to attempt to do the 
same thing, so would be interested to hear the answer. 

Any ideas OSG community?

Thanks, 
Andrew

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





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


Re: [osg-users] Infinite Grid in OSG

2009-08-10 Thread Andrew Thompson
Hi,

Well, that was simple


Code:

virtual osg::BoundingBox computeBound() const
{
   osg::BoundingBox bbox;

   // Compute the min/max X and Y values for the grid
   float miny = (m_posY-(m_vHeight/2*m_zoom));
   float maxy = (m_posY+(m_vHeight/2*m_zoom));
   float minx = (m_posX-(m_vWidth/2*m_zoom));
   float maxx = (m_posX+(m_vWidth/2*m_zoom));

   bbox.set(minx, miny, -0.1, maxx, maxy, 0.1);

   return bbox;
}




That fixed it, no more clipping. 

Thank you!
Andrew

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





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


Re: [osg-users] Infinite Grid in OSG

2009-08-10 Thread Andrew Thompson
Hi Chris, 

Thanks for the heads up, I was digging around and found the drawImplementation 
method in Drawable myself so decided to give it a go. However I've had less 
than spectacular results!

My first test was to take the code from ShapeDrawable that draws a box. Here it 
is for completeness sake


Code:


void drawImplementation(osg::RenderInfo & renderInfo) const
{
   // evaluate hints
   bool createBody = true;
   bool createTop = true;
   bool createBottom = true;

   float dx = 3;
   float dy = 3;
   float dz = 3; 

   glColor3ub(60,60,60);
   glPushMatrix();

   glTranslatef(10,10,10);

   glBegin(GL_QUADS);

   if (createBody) {
  // -ve y plane
  glNormal3f(0.0f,-1.0f,0.0f);

  glTexCoord2f(0.0f,1.0f);
  glVertex3f(-dx,-dy,dz);

  glTexCoord2f(0.0f,0.0f);
  glVertex3f(-dx,-dy,-dz);

  glTexCoord2f(1.0f,0.0f);
  glVertex3f(dx,-dy,-dz);

  glTexCoord2f(1.0f,1.0f);
  glVertex3f(dx,-dy,dz);

  // +ve y plane
  glNormal3f(0.0f,1.0f,0.0f);

  glTexCoord2f(0.0f,1.0f);
  glVertex3f(dx,dy,dz);

  glTexCoord2f(0.0f,0.0f);
  glVertex3f(dx,dy,-dz);

  glTexCoord2f(1.0f,0.0f);
  glVertex3f(-dx,dy,-dz);

  glTexCoord2f(1.0f,1.0f);
  glVertex3f(-dx,dy,dz);

  // +ve x plane
  glNormal3f(1.0f,0.0f,0.0f);

  glTexCoord2f(0.0f,1.0f);
  glVertex3f(dx,-dy,dz);

  glTexCoord2f(0.0f,0.0f);
  glVertex3f(dx,-dy,-dz);

  glTexCoord2f(1.0f,0.0f);
  glVertex3f(dx,dy,-dz);

  glTexCoord2f(1.0f,1.0f);
  glVertex3f(dx,dy,dz);

  // -ve x plane
  glNormal3f(-1.0f,0.0f,0.0f);

  glTexCoord2f(0.0f,1.0f);
  glVertex3f(-dx,dy,dz);

  glTexCoord2f(0.0f,0.0f);
  glVertex3f(-dx,dy,-dz);

  glTexCoord2f(1.0f,0.0f);
  glVertex3f(-dx,-dy,-dz);

  glTexCoord2f(1.0f,1.0f);
  glVertex3f(-dx,-dy,dz);
   }

   if (createTop) {
  // +ve z plane
  glNormal3f(0.0f,0.0f,1.0f);

  glTexCoord2f(0.0f,1.0f);
  glVertex3f(-dx,dy,dz);

  glTexCoord2f(0.0f,0.0f);
  glVertex3f(-dx,-dy,dz);

  glTexCoord2f(1.0f,0.0f);
  glVertex3f(dx,-dy,dz);

  glTexCoord2f(1.0f,1.0f);
  glVertex3f(dx,dy,dz);
   }

   if (createBottom) {
  // -ve z plane
  glNormal3f(0.0f,0.0f,-1.0f);

  glTexCoord2f(0.0f,1.0f);
  glVertex3f(dx,dy,-dz);

  glTexCoord2f(0.0f,0.0f);
  glVertex3f(dx,-dy,-dz);

  glTexCoord2f(1.0f,0.0f);
  glVertex3f(-dx,-dy,-dz);

  glTexCoord2f(1.0f,1.0f);
  glVertex3f(-dx,dy,-dz);
   }

   glEnd();
   glPopMatrix();
}





This results in a gray box drawn at the location 10,10,10 of size 3,3,3. 

[Image: http://i137.photobucket.com/albums/q217/andyb1979/drawImpBefore.png ]

However, if I add other objects to my scene, then the box renders incorrectly. 

[Image: http://i137.photobucket.com/albums/q217/andyb1979/drawImpAfter.png ]

At this point the subgraph looks like this, the additional objects from the 
position attitude transforms (labelled PAT) onwards are added when the cones 
are in the scene. 

[Image: http://i137.photobucket.com/albums/q217/andyb1979/Subgraph.png ]

Another example, what I actually want to do is draw a subdividing grid that 
extends to the horizon. The code for this (at present) is included below


Code:

void drawImplementation(osg::RenderInfo & renderInfo) const
{
   currentState->applyMode(GL_LIGHTING, false);
   glColor3ub(60,60,60);

   //render floor grid
   glLineWidth(1.0f);
   glBegin(GL_LINES);

   // Compute the Z location of the grid
   int zg = (int)0;
   int ystep = 100;
   int xstep = 100;

   // Compute the Y-Step depending on the current zoom factor
   if(m_zoom < 1.5)
  ystep = xstep = 10;
   if(m_zoom < 0.8)
  ystep = xstep = 5;
   if(m_zoom < 0.4)
  ystep = xstep = 2;
   if(m_zoom < 0.2)
  ystep = xstep = 1;

   // Compute the min/max X and Y values for each line
   float miny = (m_posY-(m_vHeight/2*m_zoom));
   float maxy = (m_posY+(m_vHeight/2*m_zoom));
   float minx = (m_posX-(m_vWidth/2*m_zoom));
   float maxx = (m_posX+(m_vWidth/2*m_zoom));

   // Draw lines in the Y direction
   for(int yg = (int)(miny - ((int)miny%ystep)); yg <= (int)(maxy - 
((int)maxy%ystep)); yg+=ystep){
  glColor3ub(60,60,60);
  if(yg%10 == 0){
 glEnd();
 glColor3ub(100,100,100);
 glLineWidth(2.0f);
 glBegin(GL_LINES);
  }
  if(yg%100 == 0)
 glColor3ub(180,180,180);
  glVertex3f(minx, (GLfloat)yg, (GLfloat)zg);
  glVertex3f(maxx, (GLfloat)yg, (GLfloat)zg);
  if(yg%10 == 0){
 glEnd();
 glLineWidth(1.0f);
 glBegin(GL_LINES);
  }
   }

   // Draw lines in the X direction
   for(int xg = (int)(minx - ((int)minx%xstep)); xg <= (int)(maxx - 
((int)maxx%xstep)); xg+=xstep){
  glColor3ub(60,60,60);
  if(xg%10 == 0){
 glEnd();
 glColor3ub(100,100,100);
 glLineWidth(2.0f);
 glBegin(GL_LINES);
  }
  if(xg%100 == 0)
 glColor3ub(180,18

Re: [osg-users] Infinite Grid in OSG

2009-08-07 Thread Andrew Thompson
Ok, wise advise, just since this is a grid (Rendered once) per frame, I will 
need to resize the grid lines/thicknesses/spacing on every frame (as I zoom/pan 
my scene). 

I guess I have enough to go digging now though, certainly you've given me some 
good ideas, 

Thank you, 
Andrew

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





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


Re: [osg-users] Infinite Grid in OSG

2009-08-07 Thread Andrew Thompson
Ok, so I could use a HUD and attach behind my scene - clever, I like it :-)

Now the question is, how do I get access to just glBegin/glEnd?

I was thinking of creating a class that inherits ShapeDrawable and just 
rendering my lines (I have found some legacy code that calculates the lines and 
subdivisions using simple GL calls). However I realised that was a stupid idea 
as Shapes do not draw themselves, but ShapeDrawable draws them, so I assume 
that a custom shape will not get rendered. 

Thank you!

Andrew

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





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


Re: [osg-users] Infinite Grid in OSG

2009-08-07 Thread Andrew Thompson
Edit: 

Perhaps another way of asking this question - I know how to render my grid 
using OpenGL calls, I would basically use glBegin(GL_LINES) / glEnd and draw 
the lines at the appropriate spacing and thickness. 

So the question is - is there a way to directly push something onto the GL 
rendering pipeline using OpenSceneGraph, prior to the rest of the scene being 
rendered?

Thank you,

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





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


[osg-users] Infinite Grid in OSG

2009-08-07 Thread Andrew Thompson
Hi there, 

A simple question, would anyone know how I could implement an infinite grid in 
OSG?

This is an image showing what I am trying to achieve. 

[Image: http://i137.photobucket.com/albums/q217/andyb1979/InfiniteGrid.png ]

Ideally as the user zooms in/out I would like the grid to subdivide. 

Do forgive me if this has been asked before. I found some examples about 
texturing a geode and moving it with your camera, but I need my grid to be 
static, starting at the origin, and show divisions in 1/10 unit spacing. 

Thank you!

Andrew

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





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


[osg-users] Using OSG Shadow mapping to compute a shadow map on a texture or bitmap

2009-08-07 Thread Andrew Thompson
Hi there, 

I have a rather strange problem that I would like to tackle using OSG, I wonder 
if anyone could offer some advice on whether it is possible or not?

In brief, the application I am working on must allow users to detect what parts 
of a scene containing in a large CAD model are and are not visible (ie: 
occluded) when viewed from certain vantage points. To do this, I am currently 
using line of sight calculations from my eye (Detector) to points spaced 
equally throughout the scene in three dimensions, however this is proving very 
slow. 

I could simplify my problem greatly by saying "If the vantage point, or camera, 
was a light source, what is the shadow map on a horizontal plane placed at a 
certain level?"

I was thinking to use osgShadow functionality to generate a shadow map on a 
horizontal plane of a size/location that I specify, given a light source at the 
vantage point. However, I would need to get the bitmap (or other representation 
- I need to know what parts of the plane are in shadow and what parts are not) 
of the shadow map back in order to process it. 

Some questions:

- Is it possible to get the shadow map out as a texture or bitmap?

- Would the OSG fail to deliver a shadow map if I used osgShadow and the 
graphics card didn't have the correct features (i.e. would it fall back to CPU 
rendering?)

- What method of shadow mapping would best suit this problem?

The above operation does not have to be real time, but it has to work on a 
variety of hardware, ranging from onboard Intel graphics to top-end video 
cards. I would greatly appreciate something that defaulted to render on CPU as 
opposed to a GPU only technique, and I must be able to get the shadow map 
applied to the plane out as a bitmap. 

Thank you!
Andrew

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





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


Re: [osg-users] complete copy of my scenegraph

2009-07-31 Thread Andrew Thompson
Hi,

I have no idea if deep copy will solve your problem, but if it doesn't, another 
way (albeit expensive in CPU) will be to serialize/deserialize your entire 
scene via memory streams, thereby forcing a copy operation. 

Here, I had a thread where I asked about this, 
http://forum.openscenegraph.org/viewtopic.php?t=2838

Cheers,
Andrew

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





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


Re: [osg-users] Truncated Cone with spheric base

2009-07-31 Thread Andrew Thompson
Hi there

Don't use the ShapeDrawable class, these are pretty slow and inefficient. 
Instead, draw the geometry yourself. 

Here - this function will create a cone with different top/bottom radius, and a 
length. Variables needed by the function include 

startRadius (float)
endRadius (float)
length (float)

and colour (Vec4)

Then I suggest you look at the Sphere shape to see how they calculate their 
vertices to append to the bottom of your cone (to get the rounded bottom). 
Finally you will need to add the Geometry object to a Geode and run the 
Smoothing Visitor over the node in order to create normals. 

Cheers,
Andrew

//

osg::Geometry * CCone::CreateConeGeometry()
{
// Here's our cone/cylinder implementation. We will create the 
top/bottom
// by triangle fans and the body will connect the two as a quad strip 
// 
// Y Z   
// ^/
// |  ---
// |--   --
// |   -  Top  -
// |   |--   --|
// |   |  ---  |
// |   |   |
// |   |  Body |
// |   |   |
// |   |   |
// |   |  ...  |
// |   |..   ..|
// |   | Bottom|
// |--   --
// |  ---
// o---> X
//  

float angle = 0.0f;
float angleDelta = 2.0f * osg::PI/(float)numberSegments;

// Create arrays to hold the X & Y coeffiecients that we will re-use
// throughout the creation of vertices
float * xTop = nullptr;
float * yTop = nullptr;
float * xBottom = nullptr;
float * yBottom = nullptr;

try
{
xTop = new float[numberSegments+1];
yTop = new float[numberSegments+1];
xBottom = new float[numberSegments+1];
yBottom = new float[numberSegments+1];

for (int i = 0; i < numberSegments; i++,angle -= angleDelta)
{
// Compute the cos/sin of the current angle as we 
rotate around the cylinder
float cosAngle = cosf(angle);
float sinAngle = sinf(angle);

// Compute the top/bottom locations
xTop[i] = cosAngle * endRadius;
yTop[i] = sinAngle * endRadius;

xBottom[i] = cosAngle * startRadius;
yBottom[i] = sinAngle * startRadius;
}   

// Put the last point equal to the first point so the cylinder
// is complete
xTop[numberSegments] = xTop[0];
yTop[numberSegments] = yTop[0];
xBottom[numberSegments] = xBottom[0];
yBottom[numberSegments] = yBottom[0];

// Compute the number of vertices required for the top and 
bottom
int numTopBottomVertices = numberSegments + 2;

// Compute the number of vertices required for the body
int numBodyVertices = (numberSegments + 1) * 2;

// Create an array to hold the cylinder vertices
osg::ref_ptr vertices = new osg::Vec3Array();
vertices->reserve(2 * numTopBottomVertices);


int j = 0;

// Create three primitive sets for the top, bottom and body of 
the cone
osg::ref_ptr topPrimitive = new 
osg::DrawElementsUByte(osg::PrimitiveSet::TRIANGLE_FAN);
osg::ref_ptr bottomPrimitive = new 
osg::DrawElementsUByte(osg::PrimitiveSet::TRIANGLE_FAN);
osg::ref_ptr bodyPrimitive = new 
osg::DrawElementsUByte(osg::PrimitiveSet::QUAD_STRIP);

// Allocate sufficient memory for the top/bottom and body
topPrimitive->reserve(numTopBottomVertices);
bottomPrimitive->reserve(numTopBottomVertices);
bodyPrimitive->reserve(numBodyVertices);

//
// Create the vertices and indices for the bottom
//

// Create the centre vertex in the trianglestrip that will form 
the bottom
vertices->push_back(osg::Vec3f(0.0f, 0.0f, 0.0f));  

bottomPrimitive->push_back(j++);

// Create the surrounding vertices for the bottom
for (int i = 0; i <= numberSegments; i++)
{
// Set the vertex location
vertices->push_back(osg::Vec3f(xBottom[i], yBottom[i], 
0.0f));

// Set the index to the vertex in the bottom primitive
bottomPrimitive->push_back(j++);
}

//
// Create the vertices and indices for the top
//

  

[osg-users] Perspective / Orthogonal projection matrix with CameraManipulator

2009-07-30 Thread Andrew Thompson
Hi there, 

I am using a custom CameraManipulator class (inheriting 
osgGA::MatrixManipulator) which is added to my scene after the OpenSceneGraph 
is initialised

The CameraManipulator has two member variables I've added, a Vec3d target and 
position. These are used to create a projection matrix by calling 
Matrix::makeLookAt. As the events are handled by the manipulator, I am updating 
the position/target and recomputing the matrix, then on Frame I am returning 
the constructed matrix. 

This provides a great perspective view, however I cannot work out how to 
construct an orthogonal projection using a target/position. 

In addition, I'd like to be able to change the Field Of View when I create the 
matrix.

I realise there is a Matrix::makeOrtho and Matrix::makePerspective, however I'm 
not sure how to use these with my CameraLocation/Target variables. 

Could anyone offer me some advice?

Thank you!
Andrew

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





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


Re: [osg-users] Simple way to determine if a point is inside a geometry

2009-07-30 Thread Andrew Thompson
Yep, will do, its a great start though, thanks

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





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


Re: [osg-users] Serializing / Deserializing an osg::Node to memory pointer

2009-07-30 Thread Andrew Thompson
Hi all,

An update on this problem, I've managed to solve it by the following steps

[list=]
[*]As I was operating in Debug mode, the IVE plugin required "zlib1d.dll" - so 
I copy/pasted zlib1.dll and renamed it to "d" and put this in C:\. I can 
confirm this works now in debug and release
[*]Then I do the serialization to stream as suggested above
[*]Finally, I can get a pointer to the ostringstream's string buffer and copy 
it to my destination file writer to complete the custom serialization
[/list]

/

// Create an output string stream and write the node to the stream
std::ostringstream outputStream;
osgDB::ReaderWriter::WriteResult wr = writer->writeNode(*geode, outputStream, 
0);

// Get the string containing the Geode data and the length of the string
std::string geodeString = outputStream.str();
int geodeLength = geodeString.length();

const char * pGeodeBytes = geodeString.c_str();

// Do work with pGeodeBytes




Thanks for the stringstream code!
Andrew
[/b]

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





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


Re: [osg-users] Simple way to determine if a point is inside a geometry

2009-07-30 Thread Andrew Thompson
Hi Gordon,

Thanks for your reply, I'm going to give that a go. 

First check - see if its in the bounding sphere of the PAT
Second check - go for the bounding boxes of the drawables. 

I guess I'll need to inverse transform my point by the PAT's matrix first?

Anyway good to know it's not too difficult, 

Thank you, 
Andrew

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





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


[osg-users] Simple way to determine if a point is inside a geometry

2009-07-29 Thread Andrew Thompson
Hi there, 

Given a single object in my scene graph defined by the hierachy

PositionAttitudeTransform (x1)
   |
Geode (x1)
   |
Geometry (x1)
   |
Drawables (x Many)

Is there a simple way to determine if a point location is inside the geometry, 
taking into account transforms applied by the PAT?

I am reluctant to use the intersect visitor, as the scene is very cluttered and 
I will likely get lots of intersections, and this may be time-consuming to 
determine whether the intersection was with my geometry object. 

Any ideas?

Thank you!

Andrew

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





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


Re: [osg-users] Serializing / Deserializing an osg::Node to memory pointer

2009-07-29 Thread Andrew Thompson
To clarify this problem, 

I have checked my environment variables and added the plugins directory to 
PATH, I also was missing zlib1.dll which I have copied to the bin directory. 
Now when I go to the command prompt and type 

"osgconv --format ive"

it comes back with a ReaderWriter for the IVE format, whereas before it popped 
up an error that zlib was missing. 

However ...

In my code it still fails to load the ReaderWriter for the IVE format. 

///
std::string plugin = 
osgDB::Registry::instance()->createLibraryNameForExtension("ive");

osgDB::Registry::LoadStatus status = 
osgDB::Registry::instance()->loadLibrary(plugin);

// Status comes back as "Not Loaded"
/

Is there anything I'm missing here? Thanks very much, 
Andrew

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





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


Re: [osg-users] Serializing / Deserializing an osg::Node to memory pointer

2009-07-29 Thread Andrew Thompson
Hi there,

I finally got around to implementing this functionality (!!) - it works great 
with "osg" as the target format, but with "ive" the getReaderWriteForExtension 
call returns null. 

I assume I am missing an environment variable or something and the OSG cannot 
find the correct plugin? For clarification, I have osgdb_ive.dll located at 
"C:\OpenSceneGraph\Bin\osgPlugins-2.8.0" and I have the following environment 
variables set (under Windows Vista 32bit)

OSG_FILE_PATH = 
C:\OpenSceneGraph\data;C:\OpenSceneGraph\data\Images;C:\OpenSceneGraph\data\fonts

OSG_ROOT = C:\OpenSceneGraph

OSGHOME = C:\OpenSceneGraph

Path = C:\OpenSceneGraph\bin;C:\OpenSceneGraph\share\OpenSceneGraph\bin\ ...

Thank you!

Andrew

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





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


Re: [osg-users] Serializing / Deserializing an osg::Node to memory pointer

2009-06-05 Thread Andrew Thompson
Hi Robert, 

Thank you for your reply. Some quick questions for you - 

By custom nodes do you mean my own classes inheriting a node? If so, no I don't 
have these. I am creating geometry inside Geode's in code, but the structure is 
very simple. 

As for the .ive format, I'll do a bit of googling to see what I come up with. 
What I'm ideally looking for is the fastest method of serializing nodes to 
memory stream (ideally binary format as opposed to text) and (of course this is 
a trade-off) the smallest file size once I save these blobs of memory.

The CAD application I am working on has to handle input data with literally 
millions of meshes. 

Thank you!

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





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


Re: [osg-users] Serializing / Deserializing an osg::Node to memory pointer

2009-06-05 Thread Andrew Thompson
... To add to the above, I just noticed osg::ReaderWriter::writeNode has an 
overload accepting a std::ostream

I imagine this is what I'm looking for - the ability to read and write nodes to 
a memory stream. 

Does anyone have any experience this this overload and can offer comment on it? 

Thank you :)

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





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


[osg-users] Serializing / Deserializing an osg::Node to memory pointer

2009-06-05 Thread Andrew Thompson
Hi there, 

This is the first time I've posted on these boards, I wonder if any of you guys 
can help me out?

I am developing a CAD application that uses OpenSceneGraph and I need to 
implement custom serialization of the CAD data to/from disk. This requires 
saving individual nodes and their children to a custom file format along with 
some other data from the app. 

Now I notice OSG has the ability to save/load multiple file formats using the 
Plugins but what I'd really like to do is save/load a node to a memory pointer, 
so the node data is held in memory as opposed to being written to a file. This 
would allow me to serialize this node data inside my own custom file format. 

Is there any way to serialize / deserialize a node to memory using the existing 
plugins? If not, how could I go about implementing this?

Thank you very much in advance, 

AndyB

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





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