Logo by Maya - Contribute your own Logo!

END OF AN ERA, FRACTALFORUMS.COM IS CONTINUED ON FRACTALFORUMS.ORG

it was a great time but no longer maintainable by c.Kleinhuis contact him for any data retrieval,
thanks and see you perhaps in 10 years again

this forum will stay online for reference
News: Support us via Flattr FLATTR Link
 
*
Welcome, Guest. Please login or register. March 28, 2024, 07:11:17 PM


Login with username, password and session length


The All New FractalForums is now in Public Beta Testing! Visit FractalForums.org and check it out!


Pages: [1]   Go Down
  Print  
Share this topic on DiggShare this topic on FacebookShare this topic on GoogleShare this topic on RedditShare this topic on StumbleUponShare this topic on Twitter
Author Topic: Camera Control via 3dmouse outputting simple rotation angles and trans values  (Read 2484 times)
0 Members and 1 Guest are viewing this topic.
tryptophan
Safarist
******
Posts: 86


« on: September 20, 2012, 10:46:11 PM »

I've been trying to learn as much as I can the past few days so I could avoid asking this question but I'm finding that I'm stuck and really need to take a math course. In the meantime though I really would like to be able to control the camera in the DE-Raytracer with a 3d mouse that outputs 6 values tx, ty, tz, rx, ry, rz where t[x,y,z] are simply position and r[x,y,z] are actual rotation angles not vectors.

I realize I can use some of the math utilities in the mathutil include but I'm not exactly sure how to set it up so I can replace the uniforms eye, target, and up in the vertex shader with variables generated from a SpaceMouse function. I'm noticing with the rotationMatrix3 function that it takes a vector "v" and a float "angle" should I use this function and input the translate value coming from the SpaceMouse into the "v" variable and then just one of the rotation angles, and then repeat the process 2 more times for the other two angles and then add or multiply the 3 matrices together? Even after doing this though I'm not sure how to get the eye, target, and up values.

I know I'm a total novice when it come to matrix transformations and I am currently learning as much as possible but I really don't know enough yet to use this knowledge to get this data into the 3 camera variables.

any help would really be appreciated

thanks
Keith
Logged
Syntopia
Fractal Molossus
**
Posts: 681



syntopiadk
WWW
« Reply #1 on: September 20, 2012, 11:58:42 PM »

You need to construct a rotation matrix from your r-vector. Now, I don't know how the Space Mouse returns the orientation, but given that it is three numbers, it is not the vector/angle representation I use. It might be Euler angles, but you have to check the documentation for that. Googling 'rotation matrix' should quickly give you the matrices for most common representations.

You also need to know if the Space Mouse return absolute orientations or relative changes. If it is an absolute orientation, you could create the rotation matrix, M, and apply it to the camera direction (which is 'Target-Eye'), and calculate a new target. I.e.:

NewTarget = Eye + M*(Target-Eye)

And send this value to the uniform in the shader.

If the changes are relative, I'd create a similar matrix M, where I accumulated the changes.

Hope this helps, Mikael.
Logged
tryptophan
Safarist
******
Posts: 86


« Reply #2 on: November 10, 2012, 10:53:49 PM »

Thanks Mikael, I understand what I need to do as far as using the matrix but I'm not sure about a couple of things.

Quote
NewTarget = Eye + M*(Target-Eye)

And send this value to the uniform in the shader.

I imagine you mean send it to the Target uniform of the shader?

I'm not exactly sure what to do about the Up uniform?

Lastly it seems that the Eye uniform would just be my tx,ty,tz values?

I got stuck with this a while ago when I first asked but now I would really like to animate the camera but can't really do it until I figure this out so any help would be hugely appreciated.

thanks
Keith
 

Logged
tryptophan
Safarist
******
Posts: 86


« Reply #3 on: April 15, 2013, 03:14:26 AM »

Hi I'm back trying to get this camera controller to work again. I'm quite a bit closer now but I can't seem to figure out what to do with the Up uniform. I've tried a few things and some come close to working but not fully. I'm still getting some flipping when passing the 90 degree point along certain axis. I'm not sure if this is even right but it does seem to mostly work just it is just the up vector that is seems to be giving me the problems now. Here is what I have so far:

Code:
uniform vec4 uResolution;
uniform vec3 camera[4];

float FOV = camera[0].x;
vec3 Eye=camera[1];
vec3 rot = camera[2];

varying vec3 dirDx; // out
varying vec3 dirDy; // out
varying vec3 from; // out
varying vec2 coord; // out
varying float zoom; // out
varying vec3 dir; // out

// Return rotation matrix
mat3  rotationAngleMatrix(vec3 r)
{
float cx = cos(radians(r.x));
float sx = sin(radians(r.x));
float cy = cos(radians(r.y));
float sy = sin(radians(r.y));
float cz = cos(radians(r.z));
float sz = sin(radians(r.z));

return mat3(cy*cz, cy*sz, -sy,
sx*sy*cz-cx*sz, cx*cz+sx*sy*sz, sx*cy,
sx*sz+cx*sy*cz, cx*sy*sz-sx*cz, cx*cy );
}

mat3 M = rotationAngleMatrix(rot);

vec3 Up = vec3(sin(radians(rot.z)),cos(radians(rot.z)),0.0);
//vec3 Up = vec3(sin(radians(rot.z)),cos(radians(rot.z)),sin(radians(rot.x)));
//vec3 Up = vec3(sin(radians(rot.z)),cos(radians(rot.z)),sin(radians(rot.x)));

vec3 target;

void main(void)
{

target = Eye + M * vec3(0.0,0.0,-0.0001);

gl_Position =  gl_ModelViewProjectionMatrix * gl_Vertex;
coord = (gl_ProjectionMatrix*gl_Vertex).xy;
coord.x*= uResolution.y/uResolution.x;
// we will only use gl_ProjectionMatrix to scale and translate, so the following should be OK.
vec2 ps =vec2(uResolution.x*gl_ProjectionMatrix[0][0], uResolution.y*gl_ProjectionMatrix[1][1]);
zoom = length(ps);
from = Eye;

vec3 Dir = normalize(target-Eye);

vec3 up = Up-dot(Dir,Up)*Dir;
up = normalize(up);
vec3 Right = normalize( cross(Dir,up));
dir = (coord.x*Right + coord.y*up )*FOV+Dir;
dirDy = ps.y*up*FOV;
dirDx = ps.x*Right*FOV;
}

I realize that the lines for getting the up vector are completely wrong but I can't really find much info on how to deal with it. Any suggestions?
Logged
Pages: [1]   Go Down
  Print  
 
Jump to:  


Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines

Valid XHTML 1.0! Valid CSS! Dilber MC Theme by HarzeM
Page created in 0.308 seconds with 25 queries. (Pretty URLs adds 0.011s, 2q)