|
[SUB] Starfield
#231845
10/17/08 09:18
10/17/08 09:18
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
Hello i decided to contribute with this little code. Istead of using a skycube with stars, that look bluured, you can use this entity based starfield. - It blinks like real stars do - Blue / Red color shift distribution - Rendered bellow all entities. - Follow player ->Add this image file to your project: DOWNLOAD IMAGE
/// NUMBER OF STARS
int star_limit=200;
//// star props
void starf_f(ENTITY* p) {
set(p,TRANSLUCENT | BRIGHT | LIGHT );
// Add random color based on red
p.red=225-random(90);
p.green=150;
p.blue=200-random(90);
while(1){
//blinking effect
p.alpha=50+random(50);
vec_set(you.pan,camera.pan);
//keep star size all the same and not by their distance to camera
you.scale_x=vec_dist(you.x,camera.x)/8200;
you.scale_y=you.scale_x;
you.scale_z=you.scale_x;
wait(1);
}
}
//// CREATOR
VECTOR star_pos;
int starf_count=0;
var angle;
while (starf_count<star_limit) {
angle=random(360);
star_pos.x=camera.x + 100000 * cos(random(360)) * cos(random(360));
star_pos.y=camera.y + 100000 *sin(random(360)) * cos(random(360));
star_pos.z=camera.z + 100000 * sin(random(360));
you=ent_createlayer("star_point.tga",SKY,2);
you.x=star_pos.x;
you.y=star_pos.y;
you.z=star_pos.z;
starf_f(you);
starf_count++;
}
}
Last edited by MMike; 10/17/08 09:26.
|
|
|
Re: [SUB] Starfield
[Re: MMike]
#238346
11/26/08 19:56
11/26/08 19:56
|
Joined: Nov 2008
Posts: 24 Nevada, USA
Kevinper
Newbie
|
Newbie
Joined: Nov 2008
Posts: 24
Nevada, USA
|
I just found this. This looks like exactly the kind of thing I'm looking for. Now to see if I can make it work (I'm an idiot with Lite-c so far).
Kevin
|
|
|
Re: [SUB] Starfield
[Re: Kevinper]
#238350
11/26/08 20:38
11/26/08 20:38
|
Joined: Nov 2008
Posts: 24 Nevada, USA
Kevinper
Newbie
|
Newbie
Joined: Nov 2008
Posts: 24
Nevada, USA
|
I got a syntax error when I ran it but deleted that last bracket and it compiled but I haven't been able to make it work yet.
Kevin
|
|
|
Re: [SUB] Starfield
[Re: Kevinper]
#238873
11/30/08 21:25
11/30/08 21:25
|
Joined: Oct 2004
Posts: 1,655
testDummy
Serious User
|
Serious User
Joined: Oct 2004
Posts: 1,655
|
/*
starfield by MMike (Lite-C)
Hello. I decided to contribute with this little code.
Instead of using a skycube with stars, that look blurred,
you can use this entity based starfield.
- It blinks like real stars do
- Blue / Red color shift distribution
- Rendered bellow all entities
- Follow player
->Add this image file to your project: star_point.tga
*/
//file: starfield.c
//images: star_point.tga
#include <acknex.h>
#include <default.c>
/// NUMBER OF STARS
int star_limit=500;
var star_dist = 30000; //-tD
//// star props
/******************************
starf_f
*******************************/
void starf_f(ENTITY* p) {
set(p,TRANSLUCENT | BRIGHT | LIGHT );
// Add random color based on red
p.red=225-random(90);
p.green=150;
p.blue=200-random(90);
while(1){
//blinking effect
p.alpha=50+random(50);
vec_set(you.pan,camera.pan);
//keep star size all the same and not by their distance to camera
you.scale_x=vec_dist(you.x,camera.x)/8200;
you.scale_y=you.scale_x;
you.scale_z=you.scale_x;
wait(1);
}
}
/******************************
starf_init
*******************************/
void starf_init() {
//// CREATOR
VECTOR star_pos;
int starf_count=0;
var angle;
while (starf_count<star_limit) {
angle=random(360);
star_pos.x=camera.x + star_dist * cos(random(360)) * cos(random(360));
star_pos.y=camera.y + star_dist *sin(random(360)) * cos(random(360));
star_pos.z=camera.z + star_dist * sin(random(360));
you=ent_createlayer("star_point.tga",SKY,2);
you.x=star_pos.x;
you.y=star_pos.y;
you.z=star_pos.z;
starf_f(you);
starf_count++;
}
}
/******************************
main
*******************************/
void main() {
vec_set(screen_color, vector(1, 1, 1));
vec_set(sky_color, vector(1, 1, 1));
video_mode = 7;
video_screen = 1;
level_load("");
wait(3);
starf_init();
}
|
|
|
Re: [SUB] Starfield
[Re: testDummy]
#239027
12/01/08 22:14
12/01/08 22:14
|
Joined: Nov 2008
Posts: 24 Nevada, USA
Kevinper
Newbie
|
Newbie
Joined: Nov 2008
Posts: 24
Nevada, USA
|
testDummy, you are ny hero. I appreciate the time and effort for the response so I can try and get a grasp on this.
Many Thanks!
Last edited by Kevinper; 12/01/08 22:15.
Kevin
|
|
|
Re: [SUB] Starfield
[Re: Kevinper]
#291162
09/23/09 16:13
09/23/09 16:13
|
Joined: Jul 2004
Posts: 1,710
MMike
OP
Serious User
|
OP
Serious User
Joined: Jul 2004
Posts: 1,710
|
|
|
|
|