Java-Gaming.org Hi !
 Featured games (90) games approved by the League of Dukes Games in Showcase (754) Games in Android Showcase (229) games submitted by our members Games in WIP (842) 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 1337 times) 0 Members and 1 Guest are viewing this topic.
Yemto

Senior Devvie

Medals: 4
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

Senior Devvie

Medals: 4
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

JGO Coder

Medals: 21

 « 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

Senior Devvie

Medals: 4
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

 DesertCoockie (33 views) 2018-05-13 18:23:11 nelsongames (75 views) 2018-04-24 18:15:36 nelsongames (69 views) 2018-04-24 18:14:32 ivj94 (752 views) 2018-03-24 14:47:39 ivj94 (82 views) 2018-03-24 14:46:31 ivj94 (622 views) 2018-03-24 14:43:53 Solater (98 views) 2018-03-17 05:04:08 nelsongames (179 views) 2018-03-05 17:56:34 Gornova (405 views) 2018-03-02 22:15:33 buddyBro (1065 views) 2018-02-28 16:59:18
 Java Gaming Resourcesby philfrei2017-12-05 19:38:37Java Gaming Resourcesby philfrei2017-12-05 19:37:39Java Gaming Resourcesby philfrei2017-12-05 19:36:10Java Gaming Resourcesby philfrei2017-12-05 19:33:10List of Learning Resourcesby elect2017-03-13 14:05:44List of Learning Resourcesby elect2017-03-13 14:04:45SF/X Librariesby philfrei2017-03-02 08:45:19SF/X Librariesby philfrei2017-03-02 08:44:05
 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