>创建自己的球体网格

通过2个角度的简单2D环(球面坐标系2笛卡尔坐标).如果想要更高的精度,可以轻松添加椭球属性(地球不是球体).如果没有,则可以对所有行星使用单球面网格,并在使用之前进行缩放…

设a为经度,b为纬度,因此从0到2 * PI [rad]循环a和b从-0.5 * PI到0.5 * PI [rad],其中PI = 3.1415 …是Pi(在C数学中). h称为M_PI).如果你的数学api使用度数然后转换为度数PI [rad] = 180.0 [deg]

>每个顶点添加必要的信息

照明法线

// just unit sphere

nx=cos(b)*cos(a);

ny=cos(b)*sin(a);

nz=sin(b);

纹理坐标(假设矩形非扭曲图像)

// just convert a,b to <0,1> range

tx=a/(2.0*PI)

ty=(b/PI)+0.5;

顶点位置

// just sphere(rx=ry=rz=r) or ellipsoid (rx=ry=equatorial and rz=polar radius)

// can also use rx*nx,ry*ny,rz*nz instead ...

x=rx*cos(b)*cos(a);

y=ry*cos(b)*sin(a);

z=rz*sin(b);

>将所有这些发送给OpenGL

所以以上都存储在一些内存空间(CPU或GPU)中,然后发送到渲染.您可以使用旧版glBegin(QUAD_STRIP); …… glEnd();或displaylist / VBO / VAO.在每个行星/身体之前绑定正确的纹理,并且不要忘记更新ModelView矩阵.这是我的坐标系看起来像:

另外看看这些相关的问答:

[edit1] C例子

//---------------------------------------------------------------------------

const int nb=15; // slices

const int na=nb<<1; // points per equator

class planet

{

public:

bool _init; // has been initiated ?

GLfloat x0,y0,z0; // center of planet [GCS]

GLfloat pos[na][nb][3]; // vertex

GLfloat nor[na][nb][3]; // normal

GLfloat txr[na][nb][2]; // texcoord

GLuint txrid; // texture id

GLfloat t; // dayly rotation angle [deg]

planet() { _init=false; txrid=0; x0=0.0; y0=0.0; z0=0.0; t=0.0; }

~planet() { if (_init) glDeleteTextures(1,&txrid); }

void init(GLfloat r,AnsiString texture); // call after OpenGL is already working !!!

void draw();

};

void planet::init(GLfloat r,AnsiString texture)

{

if (!_init) { _init=true; glGenTextures(1,&txrid); }

GLfloat x,y,z,a,b,da,db;

GLfloat tx0,tdx,ty0,tdy;// just correction if CLAMP_TO_EDGE is not available

int ia,ib;

// a,b to texture coordinate system

tx0=0.0;

ty0=0.5;

tdx=0.5/M_PI;

tdy=1.0/M_PI;

// load texture to GPU memory

if (texture!="")

{

Byte q;

unsigned int *pp;

int xs,ys,x,y,adr,*txr;

union { unsigned int c32; Byte db[4]; } c;

Graphics::TBitmap *bmp=new Graphics::TBitmap; // new bmp

bmp->LoadFromFile(texture); // load from file

bmp->HandleType=bmDIB; // allow direct access to pixels

bmp->PixelFormat=pf32bit; // set pixel to 32bit so int is the same size as pixel

xs=bmp->Width; // resolution should be power of 2

ys=bmp->Height;

txr=new int[xs*ys];

for(adr=0,y=0;y

{

pp=(unsigned int*)bmp->ScanLine[y];

for(x=0;x

{

// rgb2bgr and copy bmp -> txr[]

c.c32=pp[x];

q =c.db[2];

c.db[2]=c.db[0];

c.db[0]=q;

txr[adr]=c.c32;

}

}

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,txrid);

glPixelStorei(GL_UNPACK_ALIGNMENT, 4);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S,GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T,GL_CLAMP);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER,GL_LINEAR);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER,GL_LINEAR);

glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE,GL_MODULATE);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, xs, ys, 0, GL_RGBA, GL_UNSIGNED_BYTE, txr);

glDisable(GL_TEXTURE_2D);

delete bmp;

delete[] txr;

// texture coordinates by 1 pixel from each edge (GL_CLAMP_TO_EDGE)

tx0+=1.0/GLfloat(xs);

ty0+=1.0/GLfloat(ys);

tdx*=GLfloat(xs-2)/GLfloat(xs);

tdy*=GLfloat(ys-2)/GLfloat(ys);

}

// correct texture coordinate system (invert x)

tx0=1.0-tx0; tdx=-tdx;

da=(2.0*M_PI)/GLfloat(na-1);

db= M_PI /GLfloat(nb-1);

for (ib=0,b=-0.5*M_PI;ib

for (ia=0,a= 0.0 ;ia

{

x=cos(b)*cos(a);

y=cos(b)*sin(a);

z=sin(b);

nor[ia][ib][0]=x;

nor[ia][ib][1]=y;

nor[ia][ib][2]=z;

pos[ia][ib][0]=r*x;

pos[ia][ib][1]=r*y;

pos[ia][ib][2]=r*z;

txr[ia][ib][0]=tx0+(a*tdx);

txr[ia][ib][1]=ty0+(b*tdy);

}

}

void planet::draw()

{

if (!_init) return;

int ia,ib0,ib1;

glMatrixMode(GL_MODELVIEW);

glPushMatrix();

glLoadIdentity();

glTranslatef(x0,y0,z0);

glRotatef(90.0,1.0,0.0,0.0); // rotate planets z axis (North) to OpenGL y axis (Up)

glRotatef(-t,0.0,0.0,1.0); // rotate planets z axis (North) to OpenGL y axis (Up)

glEnable(GL_TEXTURE_2D);

glBindTexture(GL_TEXTURE_2D,txrid);

glColor3f(1.0,1.0,1.0);

for (ib0=0,ib1=1;ib1

{

glBegin(GL_QUAD_STRIP);

for (ia=0;ia

{

glNormal3fv (nor[ia][ib0]);

glTexCoord2fv(txr[ia][ib0]);

glVertex3fv (pos[ia][ib0]);

glNormal3fv (nor[ia][ib1]);

glTexCoord2fv(txr[ia][ib1]);

glVertex3fv (pos[ia][ib1]);

}

glEnd();

}

glDisable(GL_TEXTURE_2D);

glMatrixMode(GL_MODELVIEW);

glPopMatrix();

}

//---------------------------------------------------------------------------

用法:

// variable to store planet (global)

planet earth;

// init after OpenGL initialisation

earth.init(1.0,"earth.bmp");

// position update

earth.x0= 0.0;

earth.y0= 0.0;

earth.z0=-20.0;

// add this to render loop

earth.draw(); // draws the planet

earth.t+=2.5; // just rotate planet by 2.5 deg each frame...

我知道它的丑陋,但它没有使用任何有趣的东西只是传统的OpenGL和Math.h(cos(),sin(),M_PI)和VCL的位图加载.所以重写你的环境,你会没事的.不要忘记每个行星都有自己的纹理,所以你需要每个行星有一个txrid,所以要么将每个行星作为单独的行星变量或重写……

java地球_java – 应用地球纹理地图的球体相关推荐

  1. java实验 月亮围绕地球转_月亮绕着地球转,地球围绕着太阳转,那么太阳围绕着什么转?...

    我们的太阳系位于银河系之中,银河系由包括太阳在内的数十亿恒星组成.所有恒星都围绕着银河系中心的一片神秘区域旋转.孩子们通常会问,如果月亮绕着地球转,地球围绕着太阳转,那么太阳围绕着什么转?这个问题问的 ...

  2. 「人眼难以承受」的美丽,在地球之外看地球

    点击上方,选择星标或置顶,不定期资源大放送! 阅读大概需要15分钟 Follow小博主,每天更新前沿干货 [导读]你从太空中看过地球吗?那颗蔚蓝色的星球是如此的美丽!2000年11月2日,人类第一次抵 ...

  3. 【源码+教程】Java课设项目_12款最热最新Java游戏项目_Java游戏开发_Java小游戏_飞翔的小鸟_王者荣耀_超级玛丽_推箱子_黄金矿工_贪吃蛇

    马上就要期末了,同学们课设做的如何了呢?本篇为大家带来了12款热门Java小游戏项目的源码和教程,助力大家顺利迎接暑假![源码+教程]Java课设项目_12款最热最新Java游戏项目_Java游戏开发 ...

  4. Java 保姆级教程——3.添加地图,地图根据人物移动

    Java 保姆级教程--3.添加地图,地图根据人物移动 注:经过上期的学习,我们学习了如何创建JFrame窗体.如何添加监听事件.根据大家给我的反馈,这一期给大家讲述:如何添加地图.地图如何根据人物移 ...

  5. (二)地理信息中对地球的描述-地球的大地水准面、地球椭球体、大地基准面

    目录 1 概述 1.1 关于本文 1.2 进一步的认识地球 1.3 地球的三级逼近 2 大地水准面.地球椭球体.大地基准面 2.1 大地水准面 2.2 地球椭球体 2.3 大地基准面 1 概述 1.1 ...

  6. java 微信 百度地图_[Java教程]H5微信通过百度地图API实现导航方式二

    [Java教程]H5微信通过百度地图API实现导航方式二 0 2017-08-01 23:53:20 要有服务器才行哦 body, html {width: 100%;height: 100%;mar ...

  7. 谷歌地球不显示地球_奇怪的地球问题

    谷歌地球不显示地球 - and not of the muddy type! --而不是泥泞的! I have a static problem so bad that I have to take ...

  8. 【小demo】 利用two.js绘制月亮围绕地球转,地球绕着太阳转

    一 原理 在Two.js中和Canvas.SVG都不同的有这么几个地方: Two.js中所有的旋转都是以自己为中心 Two.js中的旋转不会累加 Two.js中不使用定时器,使用Two.play()方 ...

  9. WEB三维地球APP三维地球

    WEB三维地球&APP三维地球 易图讯WEB三维地球&易图讯APP三维地球基于web技术全新构建,采用领先大数据.三维GIS.AI.VR.物联网.可视化等先进技术,实现浏览器和移动端上 ...

最新文章

  1. rpath和runpath的区别
  2. java 继承 意义_Java中继承,类的高级概念的知识点
  3. 城科会刘朝晖:从互联网大脑模型看城市大脑
  4. Linux下载安装配置FTP
  5. JZOJ__Day 7:【普及模拟】max
  6. 如何打开php页面跳转_php如何跳转页面
  7. mysql开启慢查询
  8. iphone NSNotificationCenter
  9. 【动态规划】完全背包问题
  10. iphone屏蔽系统更新_iOS13屏蔽系统更新升级教程
  11. WordPress搬家插件迁移网站的方法(从一台服务器搬到另一台服务器)
  12. word 宏命令 表头与图名的设置
  13. 树莓派ubuntu默认用户名密码及密码修改
  14. 在线抖音去水印,下载抖音背景音乐
  15. win 10 设置透明图表显示为黑色方块问题
  16. About Config
  17. HC05蓝牙串口通信模块
  18. 架构的原则、范式及治理
  19. 欠债还钱,天经地义: 开发团队如何还技术债?
  20. 冯诺依曼体系结构与操作系统的概念及理解

热门文章

  1. solidworks模板_SOLIDWORKS 高级BOM导出工具
  2. jQuery length和size()区别
  3. [Objective-C语言教程]数据封装(27)
  4. Linux下socket通信和epoll
  5. 整理JavaScript中,数组和字符的操作方法
  6. 算法导论-VLSI芯片测试问题
  7. 农历算法-ASP.NET(C#)(转)
  8. Android 11 无法调起微信支付解决方案
  9. Mr.J-- jQuery学习笔记(十三)--选项Tab卡
  10. PHP CURL 异步测试