• 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();


    }


    }
  • 相关阅读:
    bash :startx command not found
    RHSA-2019:1880-低危: curl 安全和BUG修复更新 及 RHSA-2019:1884-中危: libssh2
    CentOS8 安装后 无法切换中文输入法
    【centOS7】centOS7上普通用户切换root用户,相互切换
    centos8安装图解(超详细教程)
    电导率与土壤盐浓度间的计算公式
    Tlink物联网平台使用(三)
    Wireshark查看https的通讯
    docker中建立私有git服务器[gitlab]
    【转】程序员的生产力始于需求而非工具
  • 原文地址:https://www.cnblogs.com/Anzhongliu/p/6092127.html
Copyright © 2020-2023  润新知