Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
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  
  Rotating map and camera  (Read 377 times)
0 Members and 1 Guest are viewing this topic.
Offline Yemto

Junior Member


Exp: 3 years



« Posted 2013-09-01 14: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.
Offline jonjava
« Reply #1 - Posted 2013-09-01 17:43:12 »

Seems like there is a problem with your camera.

Offline Yemto

Junior Member


Exp: 3 years



« Reply #2 - Posted 2013-09-01 19: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.
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline DrZoidberg

Senior Member


Medals: 15



« Reply #3 - Posted 2013-09-01 22: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.
Offline Yemto

Junior Member


Exp: 3 years



« Reply #4 - Posted 2013-09-01 22: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?
Offline supaFool

Junior Member


Projects: 2



« Reply #5 - Posted 2013-09-01 22: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.

 

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

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
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!