Java-Gaming.org Hi !
Featured games (81)
games approved by the League of Dukes
Games in Showcase (513)
Games in Android Showcase (119)
games submitted by our members
Games in WIP (576)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Camera Rotation  (Read 1206 times)
0 Members and 1 Guest are viewing this topic.
Offline Preacher

Junior Duke




Java games rock!


« Posted 2004-01-26 10:36:49 »

Hi trying to get my head around the mechanics of how to rotate and trasform a camera usgin xith.

can't find many tutorials on it and got some code from a few posts in this forum but still i don't really understand about multipling the matrices.

I want to be able to move tha camera like in the game Black and White which im sure ye all know, so basically the camera is above the chess board (making a chess game) with its view origin towards the center of the board. when the user moves mouse to the left or right edge of the screen and clicks and drags the camera will rotate around the central axis of the board.

likewise with the top and bottom edge but the camera will tilt around the central axis of the board. also want the camera to zoom in and out from the board using the mouse wheel.

hope thats a good description of what i want to do, sorry about the none tecnical language. I dont mind doing the research myself just can't find any good tutorials on doing this sort of thing in xith or jogl, so if anyone can suggest code or web sites that would be great Smiley
Offline tom
« Reply #1 - Posted 2004-01-26 13:12:36 »

Here is the code I'm using that does what you described:
1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
18  
19  
20  
21  
22  
23  
24  
25  
26  
27  
// these are global vars
float xrot = 0; // rotation around the right axis
float yrot = 0; // rotation around the up axis
float distance = 250; // the distance of the camera from the origin

...
// this goes in the game loop
// (Mouse.dx, Mouse.dy) is the mouse movement since last frame
if (Mouse.isButtonDown(0)) {
  // update rotation when left mouse button is dragged
  xrot += Mouse.dy*0.01f;
  float max = (float)(Math.PI/2.0*0.9);
  xrot = Math.min(max, Math.max(-max, xrot));
  yrot += Mouse.dx*0.01f;
} else if (Mouse.isButtonDown(1)) {
  // update distance when right mouse button is dragged
  distance -= distance * Mouse.dy/100;
}

// calculate position of camera using cos and sin
float cos = (float)Math.cos(xrot);
float x = cos*(float)Math.cos(yrot) * distance;
float y =     (float)Math.sin(xrot) * distance;
float z = cos*(float)Math.sin(yrot) * distance;

// feed the position to the lookAt function. We are looking at the center of the world
GLU.gluLookAt(x, y, z, 0, 0, 0, 0, 1, 0);


Just replace GLU.gluLookAt with view.getTransform().lookAt()

It is possible to extend this so that also can move on the viewing plane. That is move right, left, up and down. But it's a little bit more complicated. But I can give you the details if you need it.

Offline Preacher

Junior Duke




Java games rock!


« Reply #2 - Posted 2004-01-26 13:16:17 »

I think thats all i need i'll try it out tonight thanks very much Smiley
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline aNt

Senior Duke




AFK


« Reply #3 - Posted 2004-01-27 04:58:01 »

tom tom tom go for it Smiley
Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

Longarmx (44 views)
2014-10-17 03:59:02

Norakomi (34 views)
2014-10-16 15:22:06

Norakomi (27 views)
2014-10-16 15:20:20

lcass (31 views)
2014-10-15 16:18:58

TehJavaDev (61 views)
2014-10-14 00:39:48

TehJavaDev (61 views)
2014-10-14 00:35:47

TehJavaDev (51 views)
2014-10-14 00:32:37

BurntPizza (67 views)
2014-10-11 23:24:42

BurntPizza (39 views)
2014-10-11 23:10:45

BurntPizza (81 views)
2014-10-11 22:30:10
Understanding relations between setOrigin, setScale and setPosition in libGdx
by mbabuskov
2014-10-09 22:35:00

Definite guide to supporting multiple device resolutions on Android (2014)
by mbabuskov
2014-10-02 22:36:02

List of Learning Resources
by Longor1996
2014-08-16 10:40:00

List of Learning Resources
by SilverTiger
2014-08-05 19:33:27

Resources for WIP games
by CogWheelz
2014-08-01 16:20:17

Resources for WIP games
by CogWheelz
2014-08-01 16:19:50

List of Learning Resources
by SilverTiger
2014-07-31 16:29:50

List of Learning Resources
by SilverTiger
2014-07-31 16:26:06
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!