Java-Gaming.org Hi !
 Featured games (84) games approved by the League of Dukes Games in Showcase (603) Games in Android Showcase (171) games submitted by our members Games in WIP (651) games currently in development
 News: Read the Java Gaming Resources, or peek at the official Java tutorials
Pages: [1]
 ignore  |  Print
 Rotating map and camera  (Read 604 times) 0 Members and 1 Guest are viewing this topic.
Yemto

Junior Devvie

Medals: 2
Exp: 3 years

 « Posted 2013-09-01 12:49:15 »

so I'm currently making a isometric game, and have just gotten rotating the world to work.

This is what I use to rotate the world tiles.
 1  2  3  4  5  6  7  8  9  10  11  12  13  14  15 `    public int getDrawX(){        double rad = Math.toRadians(Screen.rotateScreen);        double rotX = (Math.cos(rad) * x) - (Math.sin(rad) * y);        double rotY = (Math.sin(rad) * x) + (Math.cos(rad) * y);                return (int)((rotY * WIDTH / 2) + (rotX * WIDTH / 2));    }        public int getDrawY(){        double rad = Math.toRadians(Screen.rotateScreen);        double rotX = Math.cos(rad)*x - Math.sin(rad)*y;        double rotY = Math.sin(rad)*x + Math.cos(rad)*y;                return (int)((rotX * HEIGHT / 2) - (rotY * HEIGHT / 2) - height);    }`

and this is what I use to rotate the screen
 1  2  3  4  5  6  7  8  9  10 `        if(e.getKeyCode() == KeyEvent.VK_R){            Screen.rotateScreen = 90+Screen.rotateScreen%360;                         double rad = Math.toRadians(Screen.rotateScreen);            double newScreenX = Math.cos(rad)*Screen.offsetX - Math.sin(rad)*Screen.offsetY;            double newScreenY = Math.sin(rad)*Screen.offsetX + Math.cos(rad)*Screen.offsetY;                        Screen.offsetX = (int)newScreenX;            Screen.offsetY = (int)newScreenY;        }`

The world rotate just fine, but the screen doesn't follow the rotation.
jonjava
 « Reply #1 - Posted 2013-09-01 15:43:12 »

Seems like there is a problem with your camera.

Yemto

Junior Devvie

Medals: 2
Exp: 3 years

 « Reply #2 - Posted 2013-09-01 17:31:29 »

Seems like there is a problem with your camera.

I know. I thought the 2nd code would rotate the offset X and Y of the view/screen just fine. But It doesn't, and I have no idea why or how to fix it.

EDIT:
What happens I look on a part of the level. OffsetX: -377 and OffsetY: 374. Then press R so the level gets rotate 90 degrees. I get offsetX: -374 offsetY: -377 and see the part of the level I was watching before.
DrZoidberg

Senior Devvie

Medals: 17

 « Reply #3 - Posted 2013-09-01 20:22:29 »

Those lines look strange
 1  2 `return (int)((rotY * WIDTH / 2) + (rotX * WIDTH / 2));return (int)((rotX * HEIGHT / 2) - (rotY * HEIGHT / 2) - height);`

What is that supposed to do?
I'm guessing the key to this error is in the code you didn't post. Maybe you rotate in the wrong direction somewhere.
Yemto

Junior Devvie

Medals: 2
Exp: 3 years

 « Reply #4 - Posted 2013-09-01 20:57:54 »

Those lines look strange
 1  2 `return (int)((rotY * WIDTH / 2) + (rotX * WIDTH / 2));return (int)((rotX * HEIGHT / 2) - (rotY * HEIGHT / 2) - height);`

What is that supposed to do?
I'm guessing the key to this error is in the code you didn't post. Maybe you rotate in the wrong direction somewhere.

Those lines is to make the tiles render isometrically. What do you mean with code I didn't post?
supaFool

Junior Devvie

Projects: 2

 « Reply #5 - Posted 2013-09-01 20:59:55 »

Wouldn't you want your Camera rotating the opposite way as your tiles?

Pages: [1]
 ignore  |  Print

You cannot reply to this message, because it is very, very old.

 SHC (11 views) 2015-08-01 03:58:20 Jesse (17 views) 2015-07-29 04:35:27 Riven (38 views) 2015-07-27 16:38:00 Riven (19 views) 2015-07-27 15:35:20 Riven (22 views) 2015-07-27 12:26:13 Riven (12 views) 2015-07-27 12:23:39 BurntPizza (32 views) 2015-07-25 00:14:37 BurntPizza (43 views) 2015-07-24 22:06:39 BurntPizza (25 views) 2015-07-24 06:06:53 NoxInc (31 views) 2015-07-22 22:16:53
 theagentd 51x wessles 45x basil_ 35x orangepascal 28x KaiHH 26x ags1 21x Riven 19x mooman219 17x bornander 14x KudoDEV 13x Jesse 11x princec 11x CelestialCreator 11x klaus 11x Zaneris 9x philfrei 8x
 List of Learning Resourcesby gouessej2015-07-09 11:29:36How Do I Expand My Game?by bashfrog2015-06-14 11:34:43List of Learning Resources2015-05-31 05:37:30Intersection Methodsby Roquen2015-05-29 08:19:33List of Learning Resources2015-05-05 10:20:32How to: JGO Wikiby Mac702015-02-17 20:56:162D Dynamic Lighting2015-01-01 20:25:42How do I start Java Game Development?by gouessej2014-12-27 19:41:21
 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