473,385 Members | 1,470 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Trouble with graphics...

Hi all,

I have a problem with the graphics I'm creating for my VC application, I am using OpenGL and have created the basics of my model/graphics ok. My model contains 'hotspots' which are just points in the model were something happens if the user clicks on. I have them working fine until the model is rotated at which point I am unsure of how to update the hotspot value to reflect the new hotspot position on screen.

I am rotating the model using

glPushMatrix();
glLoadIdentity();
glRotated(ax, 1, 0, 0);
glRotated(ay, 0, 1, 0);
glMultMatrixd(m_rotation);
glGetDoublev(GL_MODELVIEW_MATRIX, m_rotation);
glPopMatrix();

where ax and ay are double values that are related to the movement of the mouse.

I think that I should use glProject/UnProject to convert between screen and world coords but am unsure how to get the new world coords for the model after rotation - I think that I would use

GLdouble mvmatrix[16];
glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);

but I'm not sure as to what to do with the values of the modelview once I get it? I don't know if this would be the best place to get an answer but there is no OpenGL section (that i'm aware of) on this forum. Any help/pointers would be greatly appreciated as I have been struggling with this for a while.

Thank you in advance.
Dec 19 '06 #1
4 1364
macklin01
145 100+
Do you have the "red book"?

Since you know the rotations, you can manually rotate the hotspot locations (by a matrix-vector multiplication) and update the hotspot locations.

The actual rotations are in Appendix F. For instance, rotation of the point (x,y,z,1) by an angle of a about the axis (1,0,0) is given by

[1,0,0,0; 0,cos(a),-sin(a),0; 0,sin(a),cos(a),0; 0,0,0,1]*[x,y,z,1]

This will give you new coordinates of your hot spot. Don't forget that the fourth coordinate of the updated point needs to be used to rescale the x, y, and z coordinates! -- Paul
Dec 19 '06 #2
Hey Paul,

Thanks for the reply, I was working on your suggestions but unfortunately I am still having trouble and was hoping you could possible point out where I'm going wrong. Here is what I have...

-----------------------------------------------------

// for rotation around x-axis
x = ((x * 1) + (y * 0) + (z * 0) + (w * 0));
y = ((x * 0) + (y * cos(xRotation)) + (z * sin(xRotation)) + (w * 0));
z = ((x * 0) + (y * -sin(xRotation)) + (z * cos(xRotation)) + (w * 0));
w = ((x * 0) + (y * 0) + (z * 0) + (w * 1));

// for rotation around y-axis
x = ((x * cos(yRotation)) + (y * 0) + (z * -sin(yRotation)) + (w * 0));
y = ((x * 0) + (y * 1) + (z * 0) + (w * 0));
z = ((x * sin(yRotation)) + (y * 0) + (z * cos(yRotation)) + (w * 0));
w = ((x * 0) + (y * 0) + (z * 0) + (w * 1));

GLdouble wx, wy, wz;
GLdouble mvmatrix[16], projmatrix[16];
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);

gluUnProject(x, y, z, mvmatrix, projmatrix, viewport, &wx, &wy, &wz);

------------------------------------------------

where x, y, z are the object coords of the particular hotspot and w = 1. xRotation and yRotation is the total rotation around the x and y axis respectively. I have used the matrix from red book as below;

Mx = [1, 0, 0, 0; 0, cos a, -sin a, 0; 0, sin a, cos a, 0; 0, 0, 0, 1] for rotation around x - glRotated(ax, 1, 0, 0) and
My = [cos a, 0, sin a, 0; 0, 1, 0, 0; -sin a, 0, cos a, 0; 0, 0, 0, 1] for rotation around the y axis - glRotated(ay, 0, 1, 0).

I know some of the lines in the code are not really necessary, just to 'show the working'! I was unsure if it was ok to do the matrix calculations like this one after another? The results I get are different from the new position of the hotspots (or at least were the ought to be)!

Any help would be greatly appreciated, thank you in advance. Cheers
Dec 21 '06 #3
macklin01
145 100+
Hey Paul,

Thanks for the reply, I was working on your suggestions but unfortunately I am still having trouble and was hoping you could possible point out where I'm going wrong. Here is what I have...

-----------------------------------------------------

// for rotation around x-axis
x = ((x * 1) + (y * 0) + (z * 0) + (w * 0));
y = ((x * 0) + (y * cos(xRotation)) + (z * sin(xRotation)) + (w * 0));
z = ((x * 0) + (y * -sin(xRotation)) + (z * cos(xRotation)) + (w * 0));
w = ((x * 0) + (y * 0) + (z * 0) + (w * 1));

// for rotation around y-axis
x = ((x * cos(yRotation)) + (y * 0) + (z * -sin(yRotation)) + (w * 0));
y = ((x * 0) + (y * 1) + (z * 0) + (w * 0));
z = ((x * sin(yRotation)) + (y * 0) + (z * cos(yRotation)) + (w * 0));
w = ((x * 0) + (y * 0) + (z * 0) + (w * 1));

GLdouble wx, wy, wz;
GLdouble mvmatrix[16], projmatrix[16];
GLint viewport[4];
glGetIntegerv(GL_VIEWPORT, viewport);
glGetDoublev(GL_MODELVIEW_MATRIX, mvmatrix);
glGetDoublev(GL_PROJECTION_MATRIX, projmatrix);

gluUnProject(x, y, z, mvmatrix, projmatrix, viewport, &wx, &wy, &wz);

------------------------------------------------

where x, y, z are the object coords of the particular hotspot and w = 1. xRotation and yRotation is the total rotation around the x and y axis respectively. I have used the matrix from red book as below;

Mx = [1, 0, 0, 0; 0, cos a, -sin a, 0; 0, sin a, cos a, 0; 0, 0, 0, 1] for rotation around x - glRotated(ax, 1, 0, 0) and
My = [cos a, 0, sin a, 0; 0, 1, 0, 0; -sin a, 0, cos a, 0; 0, 0, 0, 1] for rotation around the y axis - glRotated(ay, 0, 1, 0).

I know some of the lines in the code are not really necessary, just to 'show the working'! I was unsure if it was ok to do the matrix calculations like this one after another? The results I get are different from the new position of the hotspots (or at least were the ought to be)!

Any help would be greatly appreciated, thank you in advance. Cheers
Hmm, interesting problem. Well, the rotations are non-commutative, so the order you apply them does matter. So, you'd need to apply them in the same order as you do to the scene.

Also, if you're rotating around some other axis, do note that any rotation about an arbitrary axis is equivalent to a rotation about two easier axes, but it can be a trick to determine the new angles.

I'm not sure if I have further advice at this point; I'll try to get back to your post and give it another look as soon as I can. Thanks -- Paul
Dec 21 '06 #4
Thanks Paul, I appreciate all your help.
Dec 22 '06 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Alberto | last post by:
I'm painting an image with this sentence: e.Graphics.DrawImageUnscaled(Image, panelImage.AutoScrollPosition); As you can see, i'm painting it on a panel control. The trouble now is that I want...
0
by: melanieab | last post by:
Hi, I have a tabpage with a print button. This button tries to do a print screen, and it works fine the first time, but if I try to press print again, I get error: An unhandled exception of type...
2
by: Matthew | last post by:
I created a transparent form, but the text in my label has a black border around it. I created a new form with a label with the text color "red" and the background color of "Transparent." I added...
6
by: Nathan Sokalski | last post by:
In a recent post of mine I mentioned the inaccurate shapes drawn by FillEllipse. In the response that I recieved I was told that DrawArc had less problems, which I found to be true (I have been...
8
by: Flack | last post by:
Hey guys, In my app I have a bitmap where drawing is done and in the form's paint method I show the bitmap: private void Form1_Paint(object sender, System.Windows.Forms.PaintEventArgs e) {...
1
by: Flack | last post by:
Hey guys, Here is the scenario: I have the main form open and a background thread is running. The background thread sometimes needs access to the main forms graphics object and gets it by...
0
by: doctorlambo | last post by:
I am trying to draw onto an image in a picturebox. That works fine with this code: dim g as graphics = picturebox1.creategraphics r.drawellipse(mypen, e.X,e.Y, 1, 1) This will draw where the...
4
by: Jaap Bos | last post by:
In VB2005 I use a rectangle (50,50,910,600) into which to display my graphics. After graphing my X-Y data I want to do some measurements on that curve using a crosshair cursor. So I a made a...
0
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
14
by: James Wong | last post by:
Hi everybody, I'm facing a serious trouble relating to GDI+ generic error. The error message is "A Generic error occured in GDI+" and the following information is stored in Excepton object:...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.