Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Ilici

Space simulation problems and more... (+screenshots)

This topic is 5233 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm working on a space simulation and i've ran into some troubles: 1. When texturing a spherical planet i get these seams: I'm generating the sphere like this:
	float polyAng = 2.0f * PI / sides;
	float ang;

	float vx, vy, vz;
	int i, j;

	for (j = 0; j <= slices; j++)
	{
		ang = j * PI / slices - PI / 2.0f;
		for (i = 0; i <= sides; i++)
		{						
			vx = cos(i * polyAng) * cos(ang);
			vy = sin(ang);
			vz = sin(i * polyAng) * cos(ang);

			Vertices[j * sides + i].x = vx;
			Vertices[j * sides + i].z = vz;
			Vertices[j * sides + i].y = vy;

			TexCoords[j * sides + i].x = atan2(vx, vz) / (2 * PI) + 0.5f ; // //(float) i / sides;

			if (TexCoords[j * sides + i].x >= 1.0f) TexCoords[j * sides + i].x = 0.999f;
			TexCoords[j * sides + i].y = asin(vy) / PI + 0.5f; ////(float) j / slices;


			Normals[j * sides + i] = Vertices[j * sides + j];
		}
	}
	
	int ind = 0;
	for (j = 1; j <= sides; j++)
	{
		for (i = 0; i <= sides; i++)
		{			
			Indices[ind++] = (j - 1) * sides + i;
			Indices[ind++] =  j      * sides + i;
		}
	}	
Any ideeas? 2. I'm trying to implement some LOD technique to the planets in the following way: Calculate the visual error using that formula, then if it is greater than some treshhold, change to a more tesseled model. How to calculate rp (the projected radius)? I have D and R and the two planes of the view frustum. 3. How do i determine the visibiliy of a sphere to know how much of it is occluded. I want to be able to make a nice fade for the flare as more and more of the sun is obscured ^^ WRONG ^^ 4. How would i go about adding some nebulas? A box would seem a good ideea but how to generate one? I'd appreciate any ideeas to improve the look of the scene ! [ My Site ] [A link to gamedev] [A Link to google] [A link to nowhere] [ /*ilici*/ ] [edited by - Ilici on March 20, 2004 6:10:40 PM]

Share this post


Link to post
Share on other sites
Advertisement
I would guess your texturing problem is because you''ve got the wrong wrapping mode set. Don''t know if you''re using D3D or OpenGL but in D3D you need to set the wrapping render state:
d3dDevice->SetRenderState(D3DRS_WRAPn  , D3DWRAPCOORD_n  ); 
for the texture coordinate set you''re using and the direction you want to enable wrapping in. This tells D3D to interpolate texture coordinates such that the shortest distance from 0.99 to 0.01 is to wrap around 1.0 rather than to work backwards from .99 to .01 - what you''re seeing in your screenshot is the whole of the texture from near the right edge back to the left edge compressed across one band of triangles. Note that this is different from the wrap texture addressing mode which tells D3D how to handle coordinates outside the 0-1 range (by tiling, mirroring, clamping etc.)

Share this post


Link to post
Share on other sites


this is how it looks now - added a skybox with the nebula textures and motion blur on the stars

I''m using OpenGL, mattnewpor and since i''m doing the tex coords manually i need another solution.

One question about lighting though:


float lp[4] = {0.0f, 0.0f, 0.0f, 1.0f };
float lc[4] = {1.0f, 1.0f, 1.0f, 1.0f };
float la[4] = {0.0f, 0.0f, 0.0f, 1.0f };

glEnable(GL_LIGHT0);
glLightfv(GL_LIGHT0, GL_POSITION, lp);
glLightfv(GL_LIGHT0, GL_DIFFUSE, lc);
glLightfv(GL_LIGHT0, GL_AMBIENT, la);


This should create a point light right?

Where should i call glLightfv, right before rendering the sphere, before setting up the camera (gluLookAt), or somewhere else?




Share this post


Link to post
Share on other sites
For a point light I believe you''ll have to set the position of the light every frame after you set up the camera but before you draw anything.

Share this post


Link to post
Share on other sites
quote:
Original post by Ilici
I''m using OpenGL, mattnewpor and since i''m doing the tex coords manually i need another solution.


There must be some equivalent to the D3DRS_WRAP state that you can set in OpenGL, afraid I can''t help you with what it is though. Not sure what you mean when you say you need another solution because you''re doing the tex coords manually? This render state isn''t about D3D generating tex coords for you, it just sets up the render state so the card knows how it should handle interpolation of tex coords. It should work if you can find the equivalent state setting call for GL.

Share this post


Link to post
Share on other sites
cool effect. btw, how did u actually do the atmospheric glow? nice work so far. and the sun glare.. is it dynamic or just a texture effect for now?

Share this post


Link to post
Share on other sites
quote:
Original post by CraZeE
cool effect. btw, how did u actually do the atmospheric glow? nice work so far. and the sun glare.. is it dynamic or just a texture effect for now?


The atmospheric glow is just a billboard with a texture gradient made in Photopaint.

The sun flare is another billboard with a texture i got off the net.

Thanx for the comments!

Share this post


Link to post
Share on other sites
regarding the error calculations: i got something working, maybe its of use to you too.

it calculates the error projected on a sphere, not onto the camera plane, because that gave me the problem of a rotating camera potentionally producing a lot of huge errors. this also means there are no lod chances when rotating the camera, which is a good thing imho.


; calculate error
mx# = (e\v1\wx + e\v2\wx) / 2
my# = (e\v1\wy + e\v2\wy) / 2
mz# = (e\v1\wz + e\v2\wz) / 2

cx# = mx - camerax
cy# = my - cameray
cz# = mz - cameraz

dx# = mx * (1-e\mul)
dy# = my * (1-e\mul)
dz# = mz * (1-e\mul)

m2# = (cx^2 + cy^2 + cz^2)

cx# = cy*dz - cz*dy
cy# = cz*dx - cx*dz
cz# = cx*dy - cy*dx

e\error = Sqr(cx*cx + cy*cy + cz*cz) / m2 ;actual error


the vector m is the midpoint of an edge, c is the vector from the camera to this midpoint, d is the errorvector in worldspace, and the rest should be not too hard too understand.

Share this post


Link to post
Share on other sites
erm... try this?

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);


Damn, why is the source box so big when it''s only two lines?

Share this post


Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!