我一直试图在太阳系的openGL(使用JOGL)中实现3D动画到目前为止我有5个不同大小的行星,但我似乎有的问题是我无法在球体上添加地球纹理的地图可以任何人帮助我如何完成它?
这是我在Display方法中到目前为止的代码:
@Override
public void display(GLAutoDrawable drawable) {
GL2 gl = drawable.getGL().getGL2();
GLU glu = new GLU();
gl.glClear(GL.GL_COLOR_BUFFER_BIT);
//make sure we are in model_view mode
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
glu.gluLookAt(10,20,20,0,3,0,0, 20, 0);
//gl.glMatrixMode(GL2.GL_PROJECTION);
//glu.gluPerspective(45,1,1,25);
//render ground plane
gl.glPushMatrix();
gl.glTranslatef(-10.75f, 3.0f, -1.0f);
gl.glColor3f(0.3f, 0.5f, 1f);
GLUquadric earth = glu.gluNewQuadric();
glu.gluQuadricDrawStyle(earth, GLU.GLU_FILL);
glu.gluQuadricNormals(earth, GLU.GLU_FLAT);
glu.gluQuadricOrientation(earth, GLU.GLU_OUTSIDE);
final float radius = 3.378f;
final int slices = 89;
final int stacks = 16;
glu.gluSphere(earth, radius, slices, stacks);
glu.gluDeleteQuadric(earth);
Texture earths;
try {
earths = TextureIO.newTexture(new File("earth.png"), …Run Code Online (Sandbox Code Playgroud) 我正在尝试为一个研究项目创建一个定制的太阳系,以测试不同的数值方法并了解它们的差异。
我们正在建造自己的太阳系,而不是尝试模拟地球/太阳,因为这看起来更困难。
现在我们有太阳 M1 和地球 M2。
当我们计算重力时,F = 8.75 或 -8.75 (F = GM1M2/r^2)
当我们计算地球绕地球公转的恒定速度时,我们发现 v = 2 (v = sqrt(G(M1+M2)/r))
为了计算力的 vec2,我们使用以下代码
static double GravitationalConstant = 0.2f;//6.674e-11;
static public Vector2f GravitationalForce(SolarObject onObj, SolarObject fromObj)
{
Vector2f result = fromObj.OldPosition - onObj.OldPosition;
float distance = result.Lenght();
Console.WriteLine(distance);
result = new Vector2f(result.X / distance, result.Y / distance); // Normalized, but I've the lenght al ready so
result …Run Code Online (Sandbox Code Playgroud) 我试图在窗口中绘制一些随机点作为星星,但点数没有显示.但其他对象正确显示.
我的源代码:
#include<windows.h>
#include <GL\glut.h>
#include <math.h> // For math routines (such as sqrt & trig).
GLfloat xRotated, yRotated, zRotated;
GLdouble radius=3;
GLfloat qaBlack[] = {0.0, 0.0, 0.0, 1.0}; //Black Color
GLfloat qaGreen[] = {0.0, 1.0, 0.0, 1.0}; //Green Color
GLfloat qaWhite[] = {1.0, 1.0, 1.0, 1.0}; //White Color
GLfloat qaRed[] = {1.0, 0.0, 0.0, 1.0}; //Red Color
// Set lighting intensity and color
GLfloat qaSpecularLight[] = {1.0, 1.0, 1.0, 1.0};
GLfloat emitLight[] = {0.9, 0.9, 0.9, 0.9};
GLfloat Noemit[] …Run Code Online (Sandbox Code Playgroud) 我想制作一个以空间纹理作为背景显示地球的程序.
地球是具有地球纹理(.bmp)的3D制服.
星星的空间是纹理(.bmp).
我总结了我要做的事情:
这是加载功能:
void load(){
//Load The Shader
Shader simpleShader("src/shader.vert", "src/shader.frag");
g_simpleShader = simpleShader.program;
// Create the VAO where we store all geometry (stored in g_Vao)
g_Vao = gl_createAndBindVAO();
//Create vertex buffer for positions, colors, and indices, and bind them to shader
gl_createAndBindAttribute(&(shapes[0].mesh.positions[0]), shapes[0].mesh.positions.size() * sizeof(float), g_simpleShader, "a_vertex", 3);
gl_createIndexBuffer(&(shapes[0].mesh.indices[0]), shapes[0].mesh.indices.size() * sizeof(unsigned int));
gl_createAndBindAttribute(uvs, uvs_size, g_simpleShader, "a_uv", 2);
gl_createAndBindAttribute(normal, normal_size, g_simpleShader, "a_normal", 2);
//Unbind Everything
gl_unbindVAO();
//Store …Run Code Online (Sandbox Code Playgroud) 我想构建一个观星应用程序。现在我已经构建了一个球体并用星图覆盖它(基于天体坐标)。(https://svs.gsfc.nasa.gov/cgi-bin/details.cgi?aid=3895)
现在我有一个 json 文件,其中包含来自 YBS 的明星目录。(也基于天体坐标)。(http://tdc-www.harvard.edu/catalogs/bsc5.html)
我想将数据与星图结合起来,希望每当我的相机节点转向那个地方时,地图都显示星座的名称。但我不知道如何将数据和领域结合起来。因为球体会因用户的纬度和时间而旋转。星体数据的坐标也必须改变。
有人有建议吗?
我正在编程一个物理模拟,并且模拟系统的每个元素都描述为存储在三个中的三维(x,y,z)long double.好吧,我的精确度非常精确,我想模拟足够庞大的系统,比如太阳系.考虑到太阳位于中心,我可以进一步保持精度高于或等于毫米,我应该使用哪个测量单位?
PS:
我知道太阳系远远超过太阳 - 冥王星的距离,但是这个距离是我想在模拟中认为有效的最小尺寸
新的一天新的问题...
我按照埃里克(Eric)所说的做,并为Acceleration创建了一种方法!
看起来像这样:
static Vector2 AccelerationOfTheMoon(Vector2 position)
{
double Mm = 7.349 * Math.Pow(10, 22);
double MagnitudeOfForce()
{
double MagF = position.LengthSquared();
return MagF;
}
Vector2 ForceAsVector()
{
return position.NegativeUnitVector() * MagnitudeOfForce();
}
Vector2 acceleration = ForceAsVector() / Mm;
}
Run Code Online (Sandbox Code Playgroud)
以我的方式看,我的名为AccelerationOfTheMoon的方法会收到带有位置的向量2。现在,我想使用此向量,因此我创建了另一个方法,该方法应将我的Magnitude作为标量(双精度)返回。为此,我创建了一种方法来计算向量的幅度并将其平方。当我在ForceAsVector-Method中调用MagnitudeOfForce-Method时,我正在尝试将负单位矢量与标量相乘,并将其作为Vector2返回。
也许我在这里做得很糟糕,但是我正在努力了解Eric所做的一切,仍然需要您的帮助!
谢谢。
c# vector newtons-method numerical-methods orbital-mechanics
给定谐波级数 1 - 1/2 + 1/3 - 1/4... = ln(2),是否可以仅使用浮点值并仅使用基本运算 (+、-、 ,/)。是否有任何算法可以提高此计算的精度,而不会达到不合理的高 n 值(当前合理限制为 1e^10)
我目前拥有的:这使我得到了 8 个正确的数字 -> 0.6931471825
编辑目标是仅使用浮点数据类型 计算最精确的求和值
int main()
{
float sum = 0;
int n = 1e9;
double ans = log(2);
int i;
float r = 0;
for (i = n; i > 0; i--) {
r = i - (2*(i/2));
if(r == 0){
sum -= 1.0000000 / i;
}else{
sum += 1.0000000 / i;
}
}
printf("\n%.10f", …Run Code Online (Sandbox Code Playgroud)