COMPGROUPS.NET | Search | Post Question | Groups | Stream | About | Register

### Rotate and move cube

• Follow

Hi all, i need to rotate and move a cube in 3D scene, with 'a' - 'd'
key increase or decrease angle rotation, and with 'w'-'s' move up or
down cube in this direction.
So i can rotate the subject of my scene and walk up and down, i do not
want move camera.
i wonder if someone knows how can i do that.

(sorry 4 my english)
10x alot,
Marica
 0

On May 13, 10:47 pm, bulmac...@gmail.com wrote:
> Hi all, i need to rotate and move a cube in 3D scene, with 'a' - 'd'
> key increase or decrease angle rotation, and with 'w'-'s' move up or
> down cube in this direction.
> So i can rotate the subject of my scene and walk up and down, i do not
> want move camera.
> i wonder if someone knows how can i do that.
>

glRotate()

--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
 0

On 14 Mag, 02:17, fungus <openglMYSO...@artlum.com> wrote:
> On May 13, 10:47 pm, bulmac...@gmail.com wrote:
>
> > Hi all, i need to rotate and move a cube in 3D scene, with 'a' - 'd'
> > key increase or decrease angle rotation, and with 'w'-'s' move up or
> > down cube in this direction.
> > So i can rotate the subject of my scene and walk up and down, i do not
> > want move camera.
> > i wonder if someone knows how can i do that.
>
> glRotate()

Hem, yes I know that.
I'm in a 3D scene and do not want move camera.
This is my code where pangle is angle cube rotation, px,py,pz is cube
position,
i just want move my cube converting correctly between polar and
cartesian coordinates, moving my cube changing angle direction and
sx is 'a' key, dx is  'd' key,  down is 's' key ad up is 'w' key,
whith keyboard interaction i want only modify angle or r.

/* The function called whenever a normal key is pressed */
GLvoid keyPressed(unsigned char key, int x, int y) {
switch (key) {
case sx:
pangle -=0.5f;
break;

case dx:
pangle -=0.5f;
break;

case down:
r+=0.1;
px = r*cos(pangle);
pz = r*sin(pangle);
break;

case up:
r-=0.1;
px = r*cos(pangle);
pz = r*sin(pangle);
break;

}
}

In main draw function:
glTranslatef(px, py, pz);
glRotatef(pangle, 0.0f,1.0f,0.0f);
myfuncDrawCube();
 0

On May 14, 7:41 pm, bulmac...@gmail.com wrote:
>
> In main draw function:
>         glTranslatef(px, py, pz);
>         glRotatef(pangle, 0.0f,1.0f,0.0f);
>         myfuncDrawCube();

Try this:

glTranslatef(px, py, pz);
glRotatef(pangle, 0.0f,1.0f,0.0f);

--
<\___/>
/ O O \
\_____/  FTB.     Remove my socks for email address.
 0

How about an Arcball rotation way?

<bulmachan@gmail.com>
> Hi all, i need to rotate and move a cube in 3D scene, with 'a' - 'd'
> key increase or decrease angle rotation, and with 'w'-'s' move up or
> down cube in this direction.
> So i can rotate the subject of my scene and walk up and down, i do not
> want move camera.
> i wonder if someone knows how can i do that.
>
> (sorry 4 my english)
> 10x alot,
> Marica

 0

4 Replies
171 Views