Hyperspace Star Generator (Source Included)

BlitzMax Forums/BlitzMax Programming/Hyperspace Star Generator (Source Included)

dw817(Posted 2016) [#1]


I had originally written this code for QBasic, but when I did, it used all manner of complex calculations that today aren't really needed.

X(I) = X(I) - (MX * 5 - X(I)) / (N& / S(I) * 50 / S(I))
Y(I) = Y(I) - (MY * 5 - Y(I)) / (N& / S(I) * 50 / S(I))


The description I left for it was:

Imagine if you will, a clear night with no clouds. The stars twinkle like a thousand little diamonds in the deep sky. Then you close your eyes and feel yourself rising up to soar into the night sky at a phenomenal rate. You pause as there is a sense of wrenching vertigo in passing through the Earth's ionosophere and break free to fly by entire entire galaxies and constellations in a matter of seconds.

Coding in QBasic was certainly a lot of work. With such commands as draw image with scale and rotation in BlitzMAX, however, I can skip all that and focus right on how a single star will appear only affected by these 2 variables.

The result ? A very nice 3D star tunnel with rapid movement. Hold down SPACE to make a hyperspace effect. Written in 36-lines of code, not counting the remarks.

Enjoi !






Derron(Posted 2016) [#2]
I appended some color variation to the stars and darkened the outside of the stars (less alpha when doing lightblend).





Stars "pop" into the screen (just look at the outer parts...they just pop in).

Glowing effect is missing when "warping" (things look pixelated after a while - this is based on the approach you are using)

bye
Ron


col(Posted 2016) [#3]
Staring at the centre after a dozen pints is pretty trippy :D


dw817(Posted 2016) [#4]
Glad you like it, Dave. :D

I'm seeing the bit of color you have added Derron. Here is the code, minus the array for rotation and giving a "Star Trek The Next Generation" feel to the stars where they are tinged with purple at the tips.



This loses the 'tunnel' effect which might be considered good.

Nope, I like the tunnel, returned it.


Taron(Posted 2016) [#5]
I'm sorry, but I couldn't resist playing with this a little... hope you don't mind?! 8}



I keep altering stuff, because it's oddly relaxing and fun.


dw817(Posted 2016) [#6]
Actually this is some very fine work, Taron. Later I had planned to make a type of modern-version "Star Trek" game and moving up/down/left/right when hunting down enemy ships is definitely part of the design I wanted.

STAR TREK GAME.

Here's a challenge for you. Can you make it so acceleration can stop completely and you can move through the stars using the arrow keys w the same effect as this:

YOUTUBE VIDEO.

Notice how when you hit any of the arrow keys in this game the stars move in a stretchy 3D format, similar to the tunnel method I developed above.


Taron(Posted 2016) [#7]
ROFL, Oh man... xD
That was fun for a moment, hihihihi... red neck space pilot! xD
(The Real StarFighter)

Anyway, yeah, that's a different thing but no problem either. Fun challenge. I'll take in on a bit later today. Gotta go shopping now, but yeah, GREAT! 8D

Awww man, I'm so in the mood for this now! Sweet! Thanks, D!


Taron(Posted 2016) [#8]
Ok, so, I've just given it a quick whirl, so it's far from being clever, but it might just be a start...

It doesn't rotate, yet, just move around in 3d...



dw817(Posted 2016) [#9]
Neat, but no curious tunnel wrap-star effect like the NES "Star Voyager" has.

I'm curious to see a BlitzMAX solution to that. Really does make it interesting. If you need, I can point you to the game where you can try it Online to get a feel for the star movement.

ONLINE PLAY.

Pardon the spam, the game is there. Once it's up, try using the UP DOWN LEFT RIGHT arrow keys to see the unusual and unique behavior of the stars.


Taron(Posted 2016) [#10]
Oh, yeah, I should check that out!
I've just added heading to it and some more control. This is really fun!

Q increases acceleration potential
E decreases it
Mouse movement only rotates heading right now, but I might add the rest later, too.
It's interesting, because it's all just software 3d, while a proper GL implementation should be a heck of a lot easier and more powerful. But this is a fun challenge!

Anyway, I'll have a look for Star Voyager then! :o)




Taron(Posted 2016) [#11]
I can tell you this much... 3d rotation is not that easy, if you haven't done it for a long time or never done it in such a context. It's pretty funny, actually. I feel like a total novice again, hahaha. But I shall figure it out and seek no help... my pride forces me, hahaha. <shame>

But it already feels incredible...I've made a few changes, especially to thrust, which really give you the space flight feeling! 8D
...feeling like an idiot somehow energizes me, too, hahahaha....

Man, are you a fantastic distraction, David, thank you for getting me into this! 8)))))


Taron(Posted 2016) [#12]
Alright, I've got it... pffff... not sure, if it's elegant, but it works.
I first just rotate x and z, moving the stars into horizontal sight.
Then I pitch them for vertical orientation.
It's kinda beautiful, I think, and already fun to fly around. For my testing I made a simple little visualization of the coordinate system, orientation of the vessel, so to say.

I've updated the code to draw the stars sorted by distance, too... might be a bit slow on weaker systems?! I'm sure there is a nicer approach to this, too.
Ultimately this is all a bunch of nonsense, of course, because one would really want to do all this with the GPU. But it's a fun challenge anyway. 8}}}

OH, and I switched to fullscreen now, which is awesome fun for me, for sure! 8D




Taron(Posted 2016) [#13]
another pretty variation...
...I keep playing around with this. I've tried out some fun lines between stars, too, which is curious looking. Silly gradient approach is neat in windows mode, but fullscreen the banding just makes it ugly.




dw817(Posted 2016) [#14]
Glad you're liking this, Taron. I gave some thought to the 3D stars last night. It seems if when you are scrolling from left to right that you 'accelerate' the stars that are on the edges and 'decelerate' them when they are closer to the center, you will be able to achieve that warped star scrolling effect as seen in Star Voyager.

Your current star code is really quite interesting. Reminds me of the effects they used in Star Trek TOS (The Original Series) when they show the main screen.

I'm experimenting with getting that warp effect myself here.


Taron(Posted 2016) [#15]
Sweet, yeah, I mean, if one considers those things stars, then it's all hypermegawarpspeed, hahahaha, but well.
I almost thought exploiting that and offering target systems near which you'd have to drop out of warp. But then you'd come by planets and all that jazz. Would be so fun, too.

But, really, at the latest then I'd want to go GPU instead of this experiment. :o}

Anyhow, my code is literally 3d stars, while the NES thing most certainly was some funny hack. Clever, though.

I was thinking about altering my camera routine to create more of a warped look, too, which could be pretty exciting.

But, yeah, can't wait to see what you'll come up with!


Casaber(Posted 2016) [#16]
Those blue stars are beutiful I could look at those all night long. It feels like you're laying on the roof and are looking around watching up towards the sky.


Taron(Posted 2016) [#17]
Ahaha, thanks, yeah...isn't it enjoyable!? I'm really, really having a blast with all this. The sensation of flying through them and moving around...I can't get enough of it, either.
But, really, it gets me giddy to think about using the gpu. Millions of stars, hehehehe... and maybe even some encounters of the third kind. :o)


dw817(Posted 2016) [#18]
Maybe not quite so good as you have it. I have the movement correct, but only 2-dimensionally. I need to work the two X & Y together.




Taron(Posted 2016) [#19]
Mehehehe. I think, it's a fun effect, David. Your code is puzzling me at first glance, but I'll have a closer look later on. I know what you're after and it might be a lot easier than that! It's a fairly simple warp. You have to translate screen space to create a lens warp effect. I'll have a go later on. I just fell in love with my 3d stars up there, but they, too, could look even more exciting with a nice lens distortion.

Anyway, keep at it! Maybe you'll beat me to it! 8D

Good fun, D!


Taron(Posted 2016) [#20]
HAAAAHAHA, TRY THIS:




Taron(Posted 2016) [#21]
Here's a slightly more elaborate version...
PAGEUP/DOWN to adjust warping amount
mouse or cursor keys for movement




Taron(Posted 2016) [#22]
Even more fancified... 8}}}



dw817(Posted 2016) [#23]
By George, I think you've done it, Taron. Well coded !!

The warp effect of bending on the edges from rotating the ship is spot on. The first time I have ever seen that in code which mimics the unique effect from Star Voyager.

Also, how do you accelerate ?

Ready for a further challenge ? Examine the star movement and HUD in "Colony Wars."

https://youtu.be/KLlwfYwKBm0?t=139

Notice the stars in Colony Wars actually have long streaks when you accelerate.


Taron(Posted 2016) [#24]
I'm thinking up a way to move forward through those super-fake stars and have something that almost works, but it's a real brain-teaser. However, if you look at my code, you'll see at the bottom a line drawing routine, which already does what it takes to get the fundamentals of such an effect.

Anyway, I'll have a go at it later, why not! 8)

I'm almost ready to make a tiny little game with this thing, though.

OH, and THANKS, of course! Glad you like it! ;o)


Taron(Posted 2016) [#25]
Here's a warp speed thingy that's real fun. Use PageUp and Down to move forward or backward, engaging warp, really.



dw817(Posted 2016) [#26]
Really beautiful, Taron ! Might add lines that appear on the end of your stars to give 'em extra stretch when you're traveling superfast, so it looks sorta like the Star Wars warp.

If you are traveling forward, I notice some stars just disappear without getting bigger. It would be interesting to be able to 'sneak' up one of the stars and see it majestically fill the screen as you get closer and closer to it.

Also I noticed when you are in full reverse and release, your stars in the distance take a 'breath.' That is they move slightly forward, not sure if that's the cause of the directional warp which looks GREAT by the way !

Wow, and you say you are working on a game using this engine of yours now too ? Here is something else to consider. This was one of my favorite games growing up.

It is called STARSHIP. What makes it different from all other space flight games is - you could actually run into a star if you weren't careful, and it could happen many times during your game.

https://www.youtube.com/watch?v=EkN6BBqiIA8

The sound effects are pretty neat too. Thus the desired need for being able to play note pitches and white noise on the fly. I think Casaber was fighting this.


Taron(Posted 2016) [#27]
Oh, I wrote my own sound engine (real time synthesis) in blitzmax already. Works like a charm! 8)

I was meaning to put it all together at some point. A cute little game might be a nice opportunity.

Yeah, I have the Z velocity hooked to the warp, making even negative motion pull the stars. I could be a bit more careful about it, sure.

As for bringing stars closer to the camera, hmmmm...the trick I'm using here makes this a bit rough. Not sure how well it would do for the effect. I'd rather add other elements that could come close, you know. But I'll have a look.


Casaber(Posted 2016) [#28]
@Taron Wow any chance to see some sound code? If so I would be interested, I'm trying myself to get some live synthesis working in Bmax but have not had much success just yet.


Taron(Posted 2016) [#29]
Oh, it's not nearly as hard as you'd think. I'll make a thread about it!

But first, I finally remembered some bmax standard graphics code, including setimagehandle, which I totally forgot. So this star version has no lines, but stretched stars. Kinda fun, too...
...I've also prepared some targeting system, hehehe




dw817(Posted 2016) [#30]
Really lovely, Taron. And yes, I too am quite interested in the ability to generate raw audio in BlitzMAX.


Taron(Posted 2016) [#31]
Oh hey, I just had a look and I already wrote a post about it some years ago:
http://www.blitzmax.com/Community/posts.php?topic=95529#1102097


dw817(Posted 2016) [#32]
Once again your star routine is REALLY sweet ! I noticed when you are full tilt in acceleration, when you let go, suddenly the back stars accelerate slightly forward, not seen any other time.

You fixed it where they hiccup when you are in reverse.

Taron, regarding your audio link. Pha-hew ! What a bit of coding you have there !

Can you isolate the routine that creates and plays the sound in just a few lines of code for a usable function written here ?

Also if you have the ability of creating white noise and at any pitch or duration.


Taron(Posted 2016) [#33]
Study the buffer logic and you're good to go, but I might make a little tutorial about it. I later wrote a little bit nicer routine, I think, but it is years ago, as you can see. No telling how "cool" the routine will be now, hehehehe! 8}

Hmmmm...might be good fun to write a a tut.

As for the stars, hm, yeah...I've hooked an enemy into it for a test and it's really not there, yet, as far as I'm concerned. The first fully 3d approach is a lot nicer, I think, because you can strafe as well as rotate and have perfect orientation. This one here, though, would need some taming, I'm afraid. :P
THANKS, though!


Derron(Posted 2016) [#34]
Nice thing how this "progressed" into something new.