adding images dynamically
Code:
void CGLWindow::OnPaint()
{
if(m_hRC != NULL)
{
glPushMatrix();
float ax=10.0f; float bx=10.0f; float cx=10.0f;
float ay=18.0f; float by=18.0f; float cy=20.0f;
float az=10.0f; float bz=10.0f; float cz=10.0f;
float dx=10.0f; float ex=10.0f; float fx=10.0f;
float dy=20.0f; float ey=18.0f; float fy=18.0f;
float dz=10.0f; float ez=10.0f; float fz=10.0f;
float gx=10.0f; float hx=10.0f;
float gy=20.0f; float hy=20.0f;
float gz=10.0f; float hz=10.0f;
float c1,c2,c3; c1=1.0f;c2=1.0f;c3=1.0f;
glcube(c1,c2,c3,ax,ay,az,bx,by,bz,cx,cy,cz,dx,dy,dz
,ex,ey,ez,fx,fy,fz,gx,gy,gz,hx,hy,hz);
glPopMatrix();
............
.
.
.
........
.
.}
void CGLWindow::OnLButtonDown(UINT nFlags, CPoint point)
{
// TODO: Add your message handler code here and/or call default
yy=20*(point.x50)/3;
zz=20*(point.y207)/3;
vrot=90.0;
CWnd::OnLButtonDown(nFlags, point);
}
void CGLWindow::OnRButtonDown(UINT nFlags, CPoint point)
{
xx=20*(point.y207)/3;
P[0]=xx;
P[1]=yy;
P[2]=zz;
P[3]=Roll;
P[4]=Pitch;
P[5]=Yaw;
find_RR(Roll,Pitch,Yaw,G);
get_3angles(G,P);
FirstEncoder=G[0]90;
SecondEncoder=G[1]90;
ThirdEncoder=G[2]+72G[1]90;
FourthEncoder= G[3];
FifthEncoder=G[4];
SixthEncoder= G[5]+G[4];
vrot=0.0;
CWnd::OnRButtonDown(nFlags, point);
}
Now wen i click on left and right mouse buttons i want new cubes to be built wit new values of xx,yy and zz. Is that possible?
yes. .
OneSadCookie Wrote:yes. .*records date and message*
possibly shortest message by OSC
It's not magic, it's Ruby.
But there is that mysterious elipsis.
Well, at least now you know why OSC's at nearly threethousand posts... not that I've anything information to say in this thread
Mark Bishop

Student and freelance OS X & iOS developer
the extra period is due to the silly 10character limit. it trims off trailing space characters before counting
If your question is, "is this possible?" then OSC's answer is "yes."
Check out gluUnProject.
Nayr Wrote:*records date and message*
possibly shortest message by OSC
Plz. explain the way it has to be done....
I tried many times, but failed to have more than one time display of the cube.
you need an array, and probably a function. grab a book on basic C.
To elaborate on OSC's answer: you want to draw an arbitrary number of cubes. You have a code snippet that draws a single cube. You could make a copy of that snippet and change the variable names. Now you have twice as many variables and you can draw two cubes. Obviously after three or four of these you are going to give up.
So the first improvement is, store the cube positions in arrays. This is where OSC's comment on grabbing a book about basic C comes in.
For simplicity you can make the arrays "big enough", to draw say 50 cubes, but if you want to get fancy you can resize them onthefly every time you want to add a new cube. (Or you could find a library that helps with this. In C++ for instance you might use STL vectors.) Either way, your draw routine will loop N times, where N is the number of cubes, drawing each one.
Another improvement you should make is to store only the minimum amount of information. If all you cubes are oriented the same way and are the same size, all you need to store in your array is a single coordinate for each cube, (x,y,z). You can store this as three numbers, maybe have an array of X values, another with your Y values, and one with your Z values. But as you get deeper into OpenGL you will want to start treating everything as a vector. It's still three numbers, but they are stored and operated on as single entities. So you can have a single array to store the positions of every cube, but if you are just starting out you can use 3 arrays if you find it simpler.
So first take the code you posted and turn it into a function that is passed an x,y, and z coordinate, and draws the cube at that position. (Yep, this is the function OSC was saying you might need!) Do this by simply adding the offset passed in to the position coordinates of the cube a simple modification to the code you posted. This makes it easy to draw 2 or more cubes, so try it and pat yourself on the back when it works.
Then learn about arrays so you can store a new coordinate every time the user clicks somewhere, and draw a cube at each position.
(Josh's answer about gluUnProject is how to take an x,y coordinate where the user clicked on the screen and turn it into three dimensional coordinates. I think for now you should start simple: draw all the cubes at the same z depth and just figure out what x & y to use. )
Hope this helps. Hopefully you would have figured out what OSC meant by learning arrays and then figuring out how they apply to your situation, but maybe I've saved you some time.
So the first improvement is, store the cube positions in arrays. This is where OSC's comment on grabbing a book about basic C comes in.
For simplicity you can make the arrays "big enough", to draw say 50 cubes, but if you want to get fancy you can resize them onthefly every time you want to add a new cube. (Or you could find a library that helps with this. In C++ for instance you might use STL vectors.) Either way, your draw routine will loop N times, where N is the number of cubes, drawing each one.
Another improvement you should make is to store only the minimum amount of information. If all you cubes are oriented the same way and are the same size, all you need to store in your array is a single coordinate for each cube, (x,y,z). You can store this as three numbers, maybe have an array of X values, another with your Y values, and one with your Z values. But as you get deeper into OpenGL you will want to start treating everything as a vector. It's still three numbers, but they are stored and operated on as single entities. So you can have a single array to store the positions of every cube, but if you are just starting out you can use 3 arrays if you find it simpler.
So first take the code you posted and turn it into a function that is passed an x,y, and z coordinate, and draws the cube at that position. (Yep, this is the function OSC was saying you might need!) Do this by simply adding the offset passed in to the position coordinates of the cube a simple modification to the code you posted. This makes it easy to draw 2 or more cubes, so try it and pat yourself on the back when it works.
Then learn about arrays so you can store a new coordinate every time the user clicks somewhere, and draw a cube at each position.
(Josh's answer about gluUnProject is how to take an x,y coordinate where the user clicked on the screen and turn it into three dimensional coordinates. I think for now you should start simple: draw all the cubes at the same z depth and just figure out what x & y to use. )
Hope this helps. Hopefully you would have figured out what OSC meant by learning arrays and then figuring out how they apply to your situation, but maybe I've saved you some time.
Measure twice, cut once, curse three or four times.
Possibly Related Threads...
Thread:  Author  Replies:  Views:  Last Post  
Dynamically swapping between RAM and VRAM  Shunter  7  4,154 
May 22, 2009 11:44 AM Last Post: backslash 

Adding Height Segments to a polygon..!!  leodeus  13  6,620 
Oct 24, 2005 08:24 AM Last Post: leodeus 