zoukankan      html  css  js  c++  java
  • openGL es2.0 创建方向方体

    package com.gzdxid.utils;


    public class DrawCubeTextureLight {


    private DrawRectTextureLight frontRect = null;
    private DrawRectTextureLight leftRect = null;
    private DrawRectTextureLight bottomRect = null;
    private int flag;
    private float halfWidth;
    private float halfHeight;
    private float halfLength;
    final float tzz = 0.1f;
    final float tzs=0.0f;
    // flag==0:法线朝里;flag==1:法线朝外;
    public DrawCubeTextureLight(float width,float height,float length,int mProgram, int flag) {
    frontRect = new DrawRectTextureLight(width, height,mProgram);
    leftRect=new DrawRectTextureLight(height, length, mProgram);
    bottomRect=new DrawRectTextureLight(width, length, mProgram);
    this.flag = flag;
    this.halfWidth=width/2;
    this.halfHeight=height/2;
    this.halfLength=length/2;
    }


    // textureId:up-down-left-right-front-back
    public void drawSelf(int[] textureId) {
    switch (flag) {
    case 0:
    drawCube0(textureId);
    break;
    case 1:
    drawCube1(textureId);
    break;
    }
    }


    private void drawCube0(int[] textureId) {
    // TODO Auto-generated method stub
    // up
    MatrixState.pushMatrix();
    MatrixState.translate(0, halfHeight - tzz, 0);
    MatrixState.rotate(90, 1, 0, 0);
    bottomRect.drawSelf(textureId[0]);
    MatrixState.popMatrix();


    // down
    MatrixState.pushMatrix();
    MatrixState.translate(0, -halfHeight + tzz, 0);
    MatrixState.rotate(-90, 1, 0, 0);
    bottomRect.drawSelf(textureId[1]);
    MatrixState.popMatrix();


    // left
    MatrixState.pushMatrix();
    MatrixState.translate(-halfWidth + tzz, 0, 0);
    MatrixState.rotate(90, 0, 1, 0);
    leftRect.drawSelf(textureId[2]);
    MatrixState.popMatrix();


    // right
    MatrixState.pushMatrix();
    MatrixState.translate(halfWidth - tzz, 0, 0);
    MatrixState.rotate(-90, 0, 1, 0);
    leftRect.drawSelf(textureId[3]);
    MatrixState.popMatrix();


    // front
    MatrixState.pushMatrix();
    MatrixState.translate(0, 0, halfLength - tzz);
    MatrixState.rotate(180, 0, 1, 0);
    frontRect.drawSelf(textureId[4]);
    MatrixState.popMatrix();


    // back
    MatrixState.pushMatrix();
    MatrixState.translate(0, 0, -halfLength + tzz);
    frontRect.drawSelf(textureId[5]);
    MatrixState.popMatrix();


    }


    private void drawCube1(int[] textureId) {


    // up
    MatrixState.pushMatrix();
    MatrixState.translate(0, halfHeight - tzs, 0);
    MatrixState.rotate(-90, 1, 0, 0);
    bottomRect.drawSelf(textureId[0]);
    MatrixState.popMatrix();


    // down
    MatrixState.pushMatrix();
    MatrixState.translate(0, -halfHeight + tzs, 0);
    MatrixState.rotate(90, 1, 0, 0);
    bottomRect.drawSelf(textureId[1]);
    MatrixState.popMatrix();


    // left
    MatrixState.pushMatrix();
    MatrixState.translate(-halfWidth + tzs, 0, 0);
    MatrixState.rotate(-90, 0, 1, 0);
    leftRect.drawSelf(textureId[3]);
    MatrixState.popMatrix();


    // right
    MatrixState.pushMatrix();
    MatrixState.translate(halfWidth - tzs, 0, 0);
    MatrixState.rotate(90, 0, 1, 0);
    leftRect.drawSelf(textureId[2]);
    MatrixState.popMatrix();


    // front
    MatrixState.pushMatrix();
    MatrixState.translate(0, 0, halfLength - tzs);
    frontRect.drawSelf(textureId[4]);
    MatrixState.popMatrix();


    // back
    MatrixState.pushMatrix();
    MatrixState.translate(0, 0, -halfLength + tzs);
    MatrixState.rotate(180, 0, 1, 0);
    frontRect.drawSelf(textureId[5]);
    MatrixState.popMatrix();


    }


    }
  • 相关阅读:
    [AST Babel] Babel Template
    [HTML5] Layout Reflow & thrashing
    [Cypress] Combine Custom Cypress Commands into a Single Custom Command
    errno , perror,strerror
    使用RMAN和控制文件备份删除归档日志的SHELL脚本--RED HAT 5 LINUX 64
    Documentation/ABI/testing/sysfs-block.txt
    003java面试笔记——【java基础篇】从团八百失败面试总结的java面试题(未完待续)
    How Many Tables
    NTP for Linux
    如何通过预加载器提升网页加载速度
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6092127.html
Copyright © 2011-2022 走看看