我正在研究太阳系,我正试图让太阳成为这个项目的核心光源,但它并没有像我想象的那样工作.
这是我没有照明的照片.

这是与照明相同的程序.

这里有一个不同的角度,你可以看到地球没有它应该的阴影(忽略月球上的红色,这是我的参考)

我不知道你是否能分辨,但看起来光在每个球体中居中,而不是在太阳中.地球上的阴影仿佛光线来自顶部.与太阳相同.这里的太阳不是光源,它只是一个球体,也被一些来源点亮.地球上的月球或地球上没有阴影.
这是绘制系统的代码
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat pos[] = { 0.0, 0.0, 1.0, 0.0 };
glEnable(GL_LIGHTING);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightf(GL_LIGHT0, GL_POSITION, pos);
//SUN
//Picture location, major radius, minor radius, major orbit, minor orbit, angle
Planet Sun ("/home/rodrtu/Desktop/SolarSystem/images/Sun.png",
100, 99, 200.0, 0.0, 0.0);
double sunOrbS = 0;
double sunRotS = rotatSpeed/10;
//orbit speed, rotation speed, moon reference coordinates (Parent planet's major and minor Axis)
Sun.displayPlanet(sunOrbS, sunRotS, 0.0, 0.0);
//EARTH
Planet Earth ("/home/rodrtu/Desktop/SolarSystem/images/EarthTopography.png", …Run Code Online (Sandbox Code Playgroud) 我有一个太阳能系统,运行在超低fps(约26).当我用行星注释出来运行程序时,我得到大约1500-2000 fps.当我添加任何行星时,它下降到大约400 fps.然后它只是从那里下坡,我添加了更多的行星.图片的大小并不大.我拥有的最大的是大约150kb.即使我减少它,fps仍然以同样的方式下降.这是太阳系的代码.
#include <Vrui/Application.h>
#include <iostream>
#include <vector>
#include "solarSystem.h"
#include "drawShape.h"
#include "planet.h"
#include "skybox.h"
using namespace std;
double orbitSpeed = 0.0;
double rotatSpeed = 0.0;
vector<Planet>planets;
/****************************************************
*
****************************************************/
SolarSystem::SolarSystem(int& argc,char**& argv)
:Vrui::Application(argc,argv)
{
//Vrui::setNavigationTransformation(Vrui::Point::origin,Vrui::Scalar(15));
}
/****************************************************
*
****************************************************/
void SolarSystem::frame(void)
{
Vrui::scheduleUpdate(Vrui::getApplicationTime()); // Aim for 125 FPS
}
/****************************************************
*
****************************************************/
void SolarSystem::createPlanets() const
{
planets.push_back(Planet("images/Sun.jpg", 696, 696, 2500, 0.0, 0.0));
planets.push_back(Planet("images/mercury.jpg", 200.44, 200.44, 57910.0, 45740.0, 0.0));
planets.push_back(Planet("images/venus.jpg", 600.05, 600.05, 108200.0, 107464.0, 177.3));
planets.push_back(Planet("images/earth.jpg", 600.37, …Run Code Online (Sandbox Code Playgroud) 我为我的项目创建了一个天空盒,它看起来就像我想要的那样; 然而,有一些问题我无法弄清楚如何修复,我已经阅读了一些关于这个主题的教程,但我找不到能帮助我的东西.第一个问题是我不知道怎么让盒子总是用我的相机移动.在下面的图像中,您可以看到我能够缩小并查看整个框,而不是仅放大/缩小太阳系并始终在背景上显示星星.

我的另一个问题是,当我放大太近时,我的背景消失了.下面的图片说明了我的意思

我知道如果我能让相机正常工作我可以解决这个问题,但这可以追溯到我的第一个问题.我不知道如何访问相机信息.
我相信我必须修改glTranslatef()并glScalef()在我的代码中从固定数字修改一个随摄像机位置变化的数字.这是我的代码:
void Skybox::displaySkybox()
{
Images::RGBImage test[6]; //6 pictures for 6 sides
test[0]=Images::readImageFile(fileName); //Top
//test[1]=Images::readImageFile(fileName);//Back
//test[2]=Images::readImageFile(fileName);//Bottom
//test[3]=Images::readImageFile(fileName);//Right
//test[4]=Images::readImageFile(fileName); //Left
//test[5]=Images::readImageFile(fileName); //Front
glEnable(GL_TEXTURE_2D);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR);
test[0].glTexImage2D(GL_TEXTURE_2D,0,GL_RGB);
// Save Current Matrix
glPushMatrix();
// Second Move the render space to the correct position (Translate)
glTranslatef(0,0,0);
// First apply scale matrix
glScalef(10000,10000,10000);
static const GLint faces[6][4] =
{
{5, 1, 2, 6}, // back
{5, 4, 0, 1}, // bottom
{0, 4, 7, 3}, // front
{4, …Run Code Online (Sandbox Code Playgroud) 我正在创建太阳系,但我不断遇到照明问题。第一个问题是月球没有在地球上投射阴影,地球也没有在月球上投射阴影。另一个问题是,照在地球和月球上的光不是来自我的太阳,而是来自轨道的中心点。我在下图中添加了红线来表达我的意思。
下图应该说明我的两个问题是什么。

这是处理灯光和行星的代码。
glDisable(GL_LIGHTING);
drawCircle(800, 720, 1, 50);
//SUN
//Picture location, major radius, minor radius, major orbit, minor orbit, angle
Planet Sun ("/home/rodrtu/Desktop/SolarSystem/images/Sun.png",
100, 99, 200.0, 0.0, 0.0);
double sunOrbS = 0;
double sunRotS = rotatSpeed/10;
cout << sunRotS << " Sun Rotation" << endl;
//orbit speed, rotation speed, moon reference coordinates (Parent planet's major and minor Axis)
Sun.displayPlanet(sunOrbS, sunRotS, 0.0, 0.0);
//Orbit path
//EARTH
GLfloat light_diffuse[] = { 1.5, 1.5, 1.5, 1.5 };
GLfloat pos[] = { 0.0, 0.0, …Run Code Online (Sandbox Code Playgroud)