Re: [osg-users] Finding position of top of rotated cylinder

2014-05-29 Thread Bush, Alex W.
Ideally you wouldn't need to determine the position of the top after rotation 
because they would all be positioned off of the same point, and then rotated 
together into place. 

Either way, I found what caused the original code to not work; it was the order 
of transformations. The PositionAttitudeTransform applies the rotation first, 
and then applies the translation (imagine the cylinder rotating in place at the 
origin, and then moving itself into position). This means we want to set the 
position of the PositionAttitudeTransform to top_of_prev_rotated_cylinder 
instead of top_of_prev_unrotated_cylinder. 

That should do the trick. . .

Alex



From: osg-users [osg-users-boun...@lists.openscenegraph.org] on behalf of Laura 
Mac [randomweirdadventure...@yahoo.com]
Sent: Wednesday, May 28, 2014 8:07 PM
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] Finding position of top of rotated cylinder

Thanks for the advice!

If I were to set the pivot point of each cylinder to the bottom of each 
cylinder, how would I determine the top of the rotated cylinder?

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





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


Re: [osg-users] Finding position of top of rotated cylinder

2014-05-28 Thread Bush, Alex W.
What exactly is wrong with the cylinders? Without seeing a short code sketch or 
at least a picture it's hard to tell what is wrong with your method.

If I had to guess, I'd probably take a look at the order of your 
transformations. Make sure your displacement of the second cylinder is 
happening before the transformation (if you reverse these you will get two 
parallel cylinders positioned on top of each other vertically).

Alex

-Original Message-
From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf 
Of Laura Mac
Sent: Wednesday, May 28, 2014 2:15 AM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] Finding position of top of rotated cylinder

HI all,

Apologies in advance for a very elementary question!

Let's say I render a vertically aligned cylinder and rotate this cylinder 20 
degrees about the x axis. 

Now let's say I render another cylinder of the same dimensions and I rotate it 
in an identical manner. 

What I want to do is place the second cylinder directly on top of the first 
cylinder such that the two cylinders resemble one long cylinder mesh. How would 
I do this?


This is the logic of what I have tried so far (and has not given visually 
accurate results):
I would need access to the position of the top of the first cylinder. I would 
be able to do this by adding the cylinder's length to its y position. However, 
this would give me the top of the non-rotated cylinder, and I am looking for 
the position at the top of the rotated cylinder.  

I am aware that I can also create a position vector of the top of the 
nonrotated cylinder and multiply this by a rotation matrix to determine the 
position vector of the top of the rotated cylinder.

Then, I assume that the rotated top position vector must correspond to the 
second cylinder's position after the second cylinder has undergone rotation. 
Thus, I must determine the initial position to set the second cylinder at in 
order to have the second cylinder's position match the top position of the 
first cylinder after rotating the second cylinder. To do this, I multiply the 
first cylinder's top position vector by the inverse of the rotation matrix, 
which I assume yields me the initial position to set the second cylinder at.

I then set the second cylinder's position as the afore-computed position 
vector, and I apply a rotation to the second cylinder.

This method is not directly placing the second cylinder above the first, 
however. Could anyone let me know what I am doing wrong?

Thanks!

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





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


Re: [osg-users] Finding position of top of rotated cylinder

2014-05-28 Thread Bush, Alex W.
Sorry, I spent a little time looking over your code, but I couldn't immediately 
pick out what was wrong with it. For simplicity's sake, you could avoid the 
creation of rot_mat by just using osg::Quat's multiplication operator, and then 
setting the new value of top_of_prev_unrotated_cylinder directly to 
top_of_new_unrotated_cylinder (saves you an inverse matrix calculation). Is 
there any reason you're not using osg::Quat's makeRotate() function?

osg::PositionAttitudeTransform allows you to declare a pivot point (in local 
space), around which the rotation will occur. Perhaps adjusting the pivot point 
to be the bottom of each cylinder would fix it? Another idea might be to setup 
each cylinder so that they share a pivot point (the bottom of the first 
cylinder). If you position each cylinder by using its center point instead of 
using the position value of the osg::PositionAttitudeTransform, you just need 
to apply the same rotation to each cylinder and they will line up. Either way, 
I'd recommend testing your method with zero rotation first as a quick sanity 
check, and then adding pivot points and rotation. 

Hope that helps!

Alex

-Original Message-
From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf 
Of Laura Mac
Sent: Wednesday, May 28, 2014 10:47 AM
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] Finding position of top of rotated cylinder


Bush, Alex W. wrote:
 What exactly is wrong with the cylinders? Without seeing a short code sketch 
 or at least a picture it's hard to tell what is wrong with your method.
 
 If I had to guess, I'd probably take a look at the order of your 
 transformations. Make sure your displacement of the second cylinder is 
 happening before the transformation (if you reverse these you will get two 
 parallel cylinders positioned on top of each other vertically).
 
 Alex
 


Thanks for the response! I will provide a short sketch of a function which is 
recursively called for each cylinder rendered. I am also attaching a picture of 
what this function renders when recursively called four times. Thank you very 
much.


Code:

void Stem::make_stem_segments(float stem_len, int num_segments, int seg_index, 
float base_radius, float head_radius, osg::Vec3 top_of_prev_unrotated_cylinder, 
osg::Vec3 top_of_prev_rotated_cylinder, float rotate_degrees_second_half, float 
rotate_degrees_first_half, float random_degrees_rotation, int left) {
if (num_segments == 0)
return;

float rotation_amount;
float seg_length = stem_len / this-num_segments;

// Determine whether segment is in first or second half of stem.
if (seg_index = (this-num_segments / 2)) {
rotation_amount = rotate_degrees_second_half + 
random_degrees_rotation;
} else {
rotation_amount = rotate_degrees_first_half + 
random_degrees_rotation;
}

// Render vertical cylinder
osg::Geode* stem_geode = new osg::Geode();
osg::PositionAttitudeTransform* stem_transform =
new osg::PositionAttitudeTransform();
stem_transform-addChild(stem_geode);   
osg::Cylinder * cylinder = new osg::Cylinder(osg::Vec3(0.0, 0.0, 
seg_length / 2), base_radius, seg_length);
osg::ShapeDrawable* cylinder_drawable = new 
osg::ShapeDrawable(cylinder);
stem_geode-addDrawable(cylinder_drawable);

// Position new cylinder.

stem_transform-setPosition(osg::Vec3(top_of_prev_unrotated_cylinder.x(), 
top_of_prev_unrotated_cylinder.y(), top_of_prev_unrotated_cylinder.z()));

osg::Vec3 top_of_new_unrotated_cylinder = 
osg::Vec3(top_of_prev_unrotated_cylinder.x(), 
top_of_prev_unrotated_cylinder.y(), top_of_prev_unrotated_cylinder.z() + 
seg_length);

// Rotate cylinder.
osg::Quat rot_quat = osg::Quat(osg::DegreesToRadians(0.0f),
osg::Vec3d(0, 0, 
1)))*(osg::Quat(osg::DegreesToRadians(rotation_amount),
osg::Vec3d(1, 0, 0)))*(osg::Quat(osg::DegreesToRadians(0.0),
osg::Vec3d(0, 1, 0));

stem_transform-setAttitude(rot_quat);

const osg::Matrixd rot_mat = osg::Matrixd(rot_quat);

top_of_prev_rotated_cylinder = rot_mat * top_of_new_unrotated_cylinder;
osg::Matrixd inverse;
if (!inverse.invert(rot_mat))
std::cout  COULD NOT COMPUTE INVERSE  std::endl;

top_of_prev_unrotated_cylinder = inverse * top_of_prev_rotated_cylinder;

this-stem-addChild(stem_transform);

// Recursively make another stem segment
make_stem_segments(stem_len, num_segments - 1, seg_index + 1, 
base_radius, head_radius, top_of_prev_unrotated_cylinder, 
top_of_prev_rotated_cylinder, rotate_degrees_second_half, 
rotate_degrees_first_half, random_degrees_rotation, 1); }


[/code]

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

Re: [osg-users] Angular magnification

2014-05-23 Thread Bush, Alex W.
Hey Steven,

Your magnification is modifying the FOV of the view frustum, and thus is best 
understood as an angular magnification. This statement: 

atan(_left  /_nearClip) /_magnification

takes the left half of your horizontal field of view and scales it by your 
magnification value. Keep in mind, the actual value of your _magnification 
variable may not directly correspond to a proper angular magnification value 
(more detail here: 
http://en.wikipedia.org/wiki/Magnification#Magnification_as_a_number_.28optical_magnification.29
 ).

These pages may help too: 
https://forums.epicgames.com/threads/811228-Avoiding-FOV-for-doing-ZOOM
http://en.wikipedia.org/wiki/Perspective_distortion_(photography)


Alex
-Original Message-
From: osg-users [mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf 
Of Steven Powers
Sent: Thursday, May 22, 2014 1:22 PM
To: osg-users@lists.openscenegraph.org
Subject: [osg-users] Angular magnification

Currently I am simulating magnification by manipulating the projection matrix 
like this:



Code:
left   = nearClip * tan(atan(_left  /_nearClip)/_magnification);
right  = nearClip * tan(atan(_right /_nearClip)/_magnification);
top= nearClip * tan(atan(_top   /_nearClip)/_magnification);
bottom = nearClip * tan(atan(_bottom/_nearClip)/_magnification);


_camera-setProjectionMatrixAsFrustum(left,right,bottom,top,nearClip,farClip);





I've been posed a question as to whether this method of magnification is 
angular or linear. Does anyone know the answer to this question?

Cheers,
Steven

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





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


Re: [osg-users] [3rdparty] SpeedTree 6.0 integration

2014-03-21 Thread Bush, Alex W.
My group is also implementing SpeedTree and having some trouble. Any help would 
be greatly appreciated. I managed to isolate OSG's OpenGL state by enabling 
glPush/glPop statements in the SpeedTree library (I know this isn't optimal), 
but I still can't get the 3D trees to render. Billboard trees are working 
(minus smooth fading between angles).

Alex

-Original Message-
From: osg-users-boun...@lists.openscenegraph.org 
[mailto:osg-users-boun...@lists.openscenegraph.org] On Behalf Of Daniel Schmid
Sent: Friday, March 21, 2014 2:03 AM
To: osg-users@lists.openscenegraph.org
Subject: Re: [osg-users] [3rdparty] SpeedTree 6.0 integration

Hi Michael

I wonder if your SpeedTree and terrain rendering is doing ok? We are about to 
integrate SpeedTree and we use paged/tiled terrain aswell.

Can you provide example code of how you integrated the SpeedTree classes and 
shaders into OSG? and also share some insights on the issues you faced?

I would be grateful!

Cheers,
Daniel

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





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