Wisdom8888 / beginning-android-games

Automatically exported from code.google.com/p/beginning-android-games
0 stars 0 forks source link

[Chapter 7] glTranslatef in BobTest.java gets Bobs off the screen #33

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?
1. Run BobTest

What is the expected output? What do you see instead?

100 Bobs should be bouncing around the screen but instead only some Bobs are 
seen "flying away" upwards (if you get lucky).

Problem:
The y-component of the coordinate system used for the Bob objects in Bob.java 
is opposite to the coordinate system on the actual screen.

Proposed solution: 
Suggested change 1:

Page 339 (BobTest.java)
Change:
gl.glTranslatef(bobs[i].x, bobs[i].y, 0);

to:
gl.glTranslatef(bobs[i].x, -1 * bobs[i].y, 0);

There is other (minor, non-critical) issue on that same class,  NUM_BOBS value 
is ignored when Bob objects are instantiated.

Suggested change 2:
Page 338 (BobTest.java)
Change:

bobs = new Bob[100];
for(int i = 0; i < 100; i++) {
bobs[i] = new Bob();
}

to

bobs = new Bob[NUM_BOBS];
for (int i = 0; i < NUM_BOBS; i++) {
bobs[i] = new Bob();
}

Great book!!!

Original issue reported on code.google.com by eduardo...@gmail.com on 27 Sep 2011 at 7:12

GoogleCodeExporter commented 8 years ago
hi...i've tried by multipling negative y. But it's still the same, it's just 
changed direction, now they disappear on the bottom.

Original comment by fabioci...@gmail.com on 28 Oct 2011 at 9:50

GoogleCodeExporter commented 8 years ago
The code to define the viewport is missing in the present method of BobTest 
class:

gl.glViewport(0, 0, glGraphics.getWidth(), glGraphics.getHeight());

Just add it to the method (right after getting the gl instance) and all 100 
Bobs will appear correctly.

Original comment by Linh.mTr...@gmail.com on 8 Nov 2011 at 4:43

GoogleCodeExporter commented 8 years ago
Try changing this "gl.glOrthof(0, 320, 0, 480, 1, -1);" to "gl.glOrthof(0, 320, 
0, -480, 1, -1);". The bobs re upside down but at least they're visible. 

Original comment by captured...@gmail.com on 28 Jun 2015 at 9:08

GoogleCodeExporter commented 8 years ago
Or even gl.glOrthof(0, 320, 480, 480+480, 1, -1);

Original comment by captured...@gmail.com on 28 Jun 2015 at 9:14