摘要: 我们继续重构,接下来我们遇到的问题是switch语句,书上说最好不要在另一个对象的属性基础上运用switch语句。如果不得不使用,也应该在对象自己的数据上使用而不是在别人的对象上使用。我们看到Rental的getCharge()里边的switch语句中的选择条件是getMovie().getPriceCode(),所以我们需要将getCharge()放到Movie类中。下边是新增加的Movie中的getCharge()和修改过的Rental中的getCharge():// method in Moviepublic double getCharge(int daysRented) { ... 阅读全文
posted @ 2012-01-08 16:41 LiLiNiuNiu 阅读(369) 评论(0) 推荐(0) 编辑
摘要: 首先我们看重构之前的,共有三个类,Customer,Movie,Rental。全都是自己写的数据类。// Rental: 表示某个顾客租了一部影片public class Rental { private Movie _movie; private int _daysRented; public Rental(Movie movie, int daysRented) { _movie = movie; _daysRented = daysRented; } public int getDaysRented() ... 阅读全文
posted @ 2012-01-08 09:29 LiLiNiuNiu 阅读(651) 评论(1) 推荐(0) 编辑
摘要: init/main.c首先我们贴上main.c中main函数的代码void main(void) /* This really IS void, no error here. */{ /* The startup routine assumes (well, ...) this *//* * Interrupts are still disabled. Do necessary setups, then * enable them */ ROOT_DEV = ORIG_ROOT_DEV; drive_info = DRIVE_INFO; ... 阅读全文
posted @ 2011-12-24 22:01 LiLiNiuNiu 阅读(1141) 评论(0) 推荐(0) 编辑
摘要: 1 public class MyRenderer implements Renderer 2 { 3 FloatBuffer verticesBuffer; 4 private final int VERTEX_SIZE = (2 + 2) * 4; 5 private AssetManager asset; 6 private int textureID; 7 8 public MyRenderer(Context context) 9 {10 asset = context.getAssets();11 ... 阅读全文
posted @ 2011-12-17 15:59 LiLiNiuNiu 阅读(565) 评论(0) 推荐(0) 编辑
摘要: public class MyRenderer implements Renderer { FloatBuffer verticesBuffer; private final int VERTEX_SIZE = (2 + 4) * 4; @Override public void onDrawFrame(GL10 gl) { gl.glViewport(0, 0, 320, 480); gl.glClear(GL10.GL_COLOR_BUFFER_BIT); gl.glMatrixMode(GL10.GL_PROJEC... 阅读全文
posted @ 2011-12-17 13:39 LiLiNiuNiu 阅读(2173) 评论(0) 推荐(0) 编辑
摘要: 1 public class MyRenderer implements Renderer 2 { 3 FloatBuffer verticesBuffer; 4 5 @Override 6 public void onDrawFrame(GL10 gl) 7 { 8 gl.glViewport(0, 0, 320, 480); 9 gl.glClear(GL10.GL_COLOR_BUFFER_BIT);10 gl.glMatrixMode(GL10.GL_PROJECTION);11 g... 阅读全文
posted @ 2011-12-17 13:30 LiLiNiuNiu 阅读(827) 评论(0) 推荐(0) 编辑
摘要: 下期预告:Android的OpenGL ES版的碰到边界返回的方块#include <GL/glut.h>// 方块的初始位置和大小GLfloat x1 = 0.0f;GLfloat y1 = 0.0f;GLfloat rsize = 25;// 在x和y方向上的步进大小GLfloat xstep = 1.0f;GLfloat ystep = 1.0f;// 追踪窗口的宽度和高度的变化GLfloat windowWidth;GLfloat windowHeight;void ChangeSize(GLsizei w, GLsizei h){ GLfloat aspectRatio; 阅读全文
posted @ 2011-12-07 21:31 LiLiNiuNiu 阅读(1102) 评论(0) 推荐(0) 编辑
摘要: // 利用ChangeSize函数在屏幕形状发生改变时重建viewport并且重新设置坐标系#include <GL/glut.h>#define WINDOW_WIDTH 640#define WINDOW_HEIGHT 480void ChangeSize(GLsizei w, GLsizei h){ GLfloat aspectRatio; // 防止被0除 if(h == 0) { h = 1; } glViewport(0, 0, w, h); // 重置坐标系统 glMatrixMode(GL_PROJECTION);... 阅读全文
posted @ 2011-12-07 19:13 LiLiNiuNiu 阅读(760) 评论(0) 推荐(0) 编辑
摘要: 首先我们在屏幕中心显示一个矩形,效果如图:// 代码没有经过优化,为的是容易理解public class OpenGLTestActivity extends Activity { GLSurfaceView glView; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); requestWindowFeature(Window.FEATURE_NO_TITLE); getWindow(... 阅读全文
posted @ 2011-12-01 09:02 LiLiNiuNiu 阅读(6504) 评论(1) 推荐(0) 编辑
摘要: 接下来的代码效果如图:// 我们定义了一个200X200的窗口// 设置视口为整个窗口// 横坐标范围为-100到100// 纵坐标范围为-100到100// 所以一个left, top, right, bottom为-50.0f, 50.0f, 50.0f, -50.0f的矩形应该在屏幕中间// 程序运行结果正如预期#include <GL/gl.h>#include <GL/glut.h>void RenderScene(){ glClear(GL_COLOR_BUFFER_BIT); glColor3f(1.0f, 0.0f, 0.0f); glRectf(-50 阅读全文
posted @ 2011-12-01 08:46 LiLiNiuNiu 阅读(3669) 评论(0) 推荐(0) 编辑