Jump to content
  • Advertisement
Sign in to follow this  
KOSH-30

starfield code in c# managed dx 9

This topic is 4809 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

Hi im trying 2 make a 3d starfield in visual c net with managed dx 9 i know it starts at 0,0 choose the points randomly and move them ,if i am correct move them on the z position ? i am using points ,this how the drawfunction looks like device.DrawPrimitives(PrimitiveType.PointList, 0, NumberItems); and this the move fuction it only show random colered points // Randomly select the position of this vertex.. Keep it within a range of 5. for(int i = 0; i < NumberItems; i++) { float xPos = (float)(Rnd.NextDouble() * 5.0f) - (float)(Rnd.NextDouble() * 5.0f); float yPos = (float)(Rnd.NextDouble() * 5.0f) - (float)(Rnd.NextDouble() * 5.0f); float zPos = (float)(Rnd.NextDouble() * 5.0f) - (float)(Rnd.NextDouble() * 5.0f); verts.SetPosition(new Vector3(xPos, yPos, zPos)); verts.Color = RandomColor.ToArgb(); } buffer.SetData(verts, 0, LockFlags.None); }

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
Hi there KOSH-30,
How are you doing?

The Problem
A starfield and it's theory

The Solution
I would suggest using sprites and the code can be from simple to difficult.
The easiest would be to simply choose random points on the screen and regenerate them as they get clipped.

1st Option
Move them z -= 10; or whatever until they reach a certain point and then just put them back at some random point in the positive z axiz. This solves 2 problems but creates a whole bunch of others..
Solves
1) It's easy to implement
2) No dynamic vertex buffers
Problems
1) It looks ugly
and alot of other problems

2nd Option
You can create a particle system called starSystem and just use a dynamic vertex buffer and give each particle(star) a lifetime). It's very effective and gives the best results.

Coming to your directly associated problem, Yes , you would move them in the Z position as for your code. It looks fine for randomly generating starting points.

I hope this helps a bit buddy.

Share this post


Link to post
Share on other sites
Hi there KOSH-30,
How are you doing?

The Problem
A starfield and it's theory

The Solution
I would suggest using sprites and the code can be from simple to difficult.
The easiest would be to simply choose random points on the screen and regenerate them as they get clipped.

1st Option
Move them z -= 10; or whatever until they reach a certain point and then just put them back at some random point in the positive z axiz. This solves 2 problems but creates a whole bunch of others..
Solves
1) It's easy to implement
2) No dynamic vertex buffers
Problems
1) It looks ugly
and alot of other problems

2nd Option
You can create a particle system called starSystem and just use a dynamic vertex buffer and give each particle(star) a lifetime). It's very effective and gives the best results.

Coming to your directly associated problem, Yes , you would move them in the Z position as for your code. It looks fine for randomly generating starting points.

I hope this helps a bit buddy.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
How about add simple meshes at positions out ahead, and then move the camera forwards? Its very simple to dispose the stars when they are behind the plane that you camera vector is normal to, and the speed is easily controled, as its just moving your camera forwards, everything stays in place... Or let the cam stay in place and move all stars towards the camera plane.

Share this post


Link to post
Share on other sites
I have been working on a simular project. With mine though I did not use it to place starts but I did use it to place planets. What I did was create a random function that would calculate the positions of the planents, this took the System size units and created a co or system based on this value. Then it randomly picked locations inside the space. But with random numbers this looked really strange most times. The next thing I did was to pass the creation code some more values, these where TooClose and MinDistance. The TooClose value ment that the planet would not have another planet that had a distance that was less then TooClose. but having the min distance ment that I wanted to have at least 1 planet that was the Min Distance from the planet being generated.

To draw them on the screen, I used a basic primitive for the planet, but in furture versions I will be texturing the planets based on the values generated.

Here is a link to my small blog post on the system, included is a link to an image that was created. XTrader Star Chart

Note that at the moment the system uses the Sample framework from the SDK.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • 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!