Java-Gaming.org    
Featured games (81)
games approved by the League of Dukes
Games in Showcase (497)
Games in Android Showcase (114)
games submitted by our members
Games in WIP (563)
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  
  Better modifying the render or moving the camera?  (Read 2496 times)
0 Members and 1 Guest are viewing this topic.
Offline elect

Junior Member





« Posted 2012-02-27 08:12:55 »

Hi all,

Since I gogled for it without finding anything interesting, I would like to ask you for some suggestions regarding if it is better to scale/translate the render itself keeping the camera position fixed or maybe moving closer/further or rotate the camera keeping the render position fixed?

I need a zooming out/in, rotation in all the 3 axes and also this kind of rotation

http://www.reknow.de/downloads/opengl/video.mp4

that is, if I first translate my render and then I apply a rotation, this rotation should consider the center always the windows center, and not the translated one
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #1 - Posted 2012-02-27 08:29:41 »

I don't quite understand what you are asking for exactly.

Also the video doesn't work, Windows Media Player gives me an error :S

Offline elect

Junior Member





« Reply #2 - Posted 2012-02-27 08:57:45 »

I don't quite understand what you are asking for exactly.

Also the video doesn't work, Windows Media Player gives me an error :S

Let's suppose I have a quad, and I want to zoom in:

What is better, moving the camera closer to the quad or moving the quad closer to the camera?


Also the video doesn't work, Windows Media Player gives me an error :S

Damn, for me it looks working
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline ra4king

JGO Kernel


Medals: 345
Projects: 3
Exp: 5 years


I'm the King!


« Reply #3 - Posted 2012-02-27 08:58:59 »

Wouldn't it make more sense to "move" the camera? The world's object's coordinates don't change, only the camera's values change.

Offline cylab

JGO Ninja


Medals: 49



« Reply #4 - Posted 2012-02-27 12:24:29 »

Actually for "zooming" you would not move anything but change the FOV in the projection...

Mathias - I Know What [you] Did Last Summer!
Offline Cero
« Reply #5 - Posted 2012-02-27 15:26:02 »

Also the video doesn't work, Windows Media Player gives me an error :S
Damn, for me it looks working

Its a techsmith codec - when you install camtasia you can encode and decode in this format, but other people cannot
so you gotta export it as a normal codec

Offline elect

Junior Member





« Reply #6 - Posted 2012-02-27 16:24:20 »

Wouldn't it make more sense to "move" the camera? The world's object's coordinates don't change, only the camera's values change.

Yep, I thought the same

Actually for "zooming" you would not move anything but change the FOV in the projection...

Thanks, but this for the perspective, for the ortho, i need to change the first four parameters, right?

Its a techsmith codec - when you install camtasia you can encode and decode in this format, but other people cannot
so you gotta export it as a normal codec

Ah, that's why, ok, I fixed it, now it should work
Offline sproingie

JGO Kernel


Medals: 202



« Reply #7 - Posted 2012-02-27 16:42:19 »

What is better, moving the camera closer to the quad or moving the quad closer to the camera?

Yes.   Grin

To elaborate, there is no camera, it is always the world that moves.  Your "camera" is really just a bounding volumes and a couple of matrix transformations that define a chunk of the world's coordinates as the part that appears on your screen.  This virtual camera is pointed at the origin and looks down the Z axis and never moves, so in order to make something appear on camera, you move everything you draw in the world into the frame.  So to truck right, you move the whole scene left, and vice versa.  To tilt up, you spin the scene's coordinates around the X axis, to pan you spin around the Y axis, and so on.

Moving an object closer to the camera will cause it to appear larger in a perspective projection, but do nothing for an orthographic projection.  To make something bigger outright, you need to use glScale, and to move and rotate, you use glTranslate and glRotate.

Offline elect

Junior Member





« Reply #8 - Posted 2012-03-07 16:15:59 »

Ok guys, actually I am stuck on my program since 2 days and I dont know what to do...

Right now, I am rendering a cylinder, I can pan and zoom using this:

1  
2  
3  
4  
5  
6  
7  
8  
display()   {
...
                          glu.gluLookAt(translationX/gLAutoDrawable.getWidth()*scale*2,
                                            -translationY/gLAutoDrawable.getHeight()*scale*2, 2,
                          translationX/gLAutoDrawable.getWidth()*scale*2,
                                            -translationY/gLAutoDrawable.getHeight()*scale*2, 0,
...
}


I can also rotate using some custom functions:

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  
28  
29  
30  
31  
32  
33  
34  
35  
36  
37  
38  
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58  
59  
60  
61  
62  
display()   {
...

glu.gluLookAt

...

gl.glMultMatrixf(currentRotation, 0);

...

}

mouseDragged()   {

...

if(rotationMode)   {
            float newRotation[] = multiply(rotationX(-dy), rotationY(-dx));
            currentRotation = multiply(currentRotation, newRotation);
            rotationX +=dx;
            rotationY +=dy;
        }
...
}

private static float[] rotationX(float angleDeg)    {
        float m[] = identity();
        float angleRad = (float)Math.toRadians(angleDeg);
        float ca = (float)Math.cos(angleRad);
        float sa = (float)Math.sin(angleRad);
        m[ 5] =  ca;
        m[ 6] =  sa;
        m[ 9] = -sa;
        m[10] =  ca;
        return m;
    }

private static float[] rotationY(float angleDeg)    {
        float m[] = identity();
        float angleRad = (float)Math.toRadians(angleDeg);
        float ca = (float)Math.cos(angleRad);
        float sa = (float)Math.sin(angleRad);
        m[ 0] =  ca;
        m[ 2] = -sa;
        m[ 8] =  sa;
        m[10] =  ca;
        return m;
    }

private static float[] multiply(float m0[], float m1[]) {
        float m[] = new float[16];
        for (int x=0; x < 4; x++)   {
            for(int y=0; y < 4; y++)    {
                m[x*4 + y] = m0[x*4+0] * m1[y+ 0] +
                             m0[x*4+1] * m1[y+ 4] +
                             m0[x*4+2] * m1[y+ 8] +
                             m0[x*4+3] * m1[y+12];
            }
        }
        return m;
    }


This special rotation was mandatory because if I use glRotate to rotate my cylinder a first time over the horizontal plane, lets say, then my modelview coordinates rotates as well, and I dont want to have this, since I still need to rotate over the vertical axes

Now, the problem is that the rotation is performed taking the modelview origin as the rotation point...

This means that if I pan (aka move the camera) I would like to see a rotation over the center of my screen, and not the center of the modelview (that has been panned)

I hope it's clear, otherwise I can post something else to illustrate it better..
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.

BurntPizza (19 views)
2014-09-19 03:14:18

Dwinin (34 views)
2014-09-12 09:08:26

Norakomi (62 views)
2014-09-10 13:57:51

TehJavaDev (87 views)
2014-09-10 06:39:09

Tekkerue (42 views)
2014-09-09 02:24:56

mitcheeb (65 views)
2014-09-08 06:06:29

BurntPizza (47 views)
2014-09-07 01:13:42

Longarmx (35 views)
2014-09-07 01:12:14

Longarmx (40 views)
2014-09-07 01:11:22

Longarmx (36 views)
2014-09-07 01:10:19
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

List of Learning Resources
by SilverTiger
2014-07-31 11:54:12

HotSpot Options
by dleskov
2014-07-08 01:59:08
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!