🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.c
Article #1748

Re: [p.i.c] ships flyin and faitin

#1748
From: fir
Date: Sat, 21 Nov 2026 07:14
165 lines
7720 bytes
Chris M. Thomasson pisze:
> On 11/20/2026 3:41 PM, fir wrote:
>> Chris M. Thomasson pisze:
>>> On 11/20/2026 12:23 AM, fir wrote:
>>>> Chris M. Thomasson pisze:
>>>>> On 11/16/2026 11:37 AM, fir wrote:
>>>>>> i toy with this 3d rasterizer and get some 3d ships (kinda like 
>>>>>> aeroplanes/jets but in space) and want to code them interesting 
>>>>>> flying behaviours
>>>>>>
>>>>>> maybe some will have some thoughts on it (then i eventually my try 
>>>>>> some ideas and post a video how it work)
>>>>>>
>>>>>> the api you need to code such behaviour is quite simple for 
>>>>>> example some basic algortihm that work is
>>>>>>
>>>>>> void FlyPass2(int i)
>>>>>> {
>>>>>>      float3 player_pos=PlayerPos();
>>>>>>      float3 to_player=sub(player_pos,bag[i].p.pos);
>>>>>>      float distance=length(to_player);
>>>>>>      if(distance<0.001f) return;
>>>>>>      normalize(&to_player);
>>>>>>
>>>>>>      if(bag[i].combat_state!='approach' && bag[i].combat_state! 
>>>>>> ='pass' && bag[i].combat_state!='turn') 
>>>>>> bag[i].combat_state='approach';
>>>>>>
>>>>>>      if(bag[i].combat_state=='approach')
>>>>>>      {
>>>>>>          YawPitchAccelerate(i,to_player,30/3);
>>>>>>          if(distance<20*150) bag[i].combat_state='pass';
>>>>>>      }
>>>>>>
>>>>>>      if(bag[i].combat_state=='pass')
>>>>>>      {
>>>>>>          YawPitchAccelerate(i,to_player,60/3);
>>>>>>          if(distance<20*70) bag[i].combat_state='turn';
>>>>>>      }
>>>>>>
>>>>>>      if(bag[i].combat_state=='turn')
>>>>>>      {
>>>>>>          float3 direction=mul(to_player,-1.0f);
>>>>>>          YawPitchAccelerate(i, direction, 45/3);
>>>>>>
>>>>>>          if(distance>20*600) bag[i].combat_state='approach';
>>>>>>      }
>>>>>> }
>>>>>>
>>>>>>
>>>>>> if c would have basic vector arithmetic it would look better
>>>>>>
>>>>>> 20*600 mean 600 meters as the world 1.0 unit is like 5 cm
>>>>>>
>>>>>> 45/3 means 45 m/s speed -as its about 60 fps so 45/3*60 = 45*20 
>>>>>> (45 meters/s)
>>>>>>
>>>>>>          YawPitchAccelerate(i, direction, 45/3);
>>>>>>
>>>>>> do most work it just make ship starting to yaw-pitch into given 
>>>>>> direction and accelerate/deacce;erate for given speed
>>>>>>
>>>>>> (it is handled by simple 'engine' which has limited angular and 
>>>>>> linear acceleration and there is also dumping factor)..
>>>>>>
>>>>>> here above it uses its max accelerations but eventually value from 
>>>>>> 0.0..1.0 can be passed if ships qould be said only use parts of 
>>>>>> its max accalarations
>>>>>>
>>>>>>
>>>>>> i need good ideas what such ships can do..i not yet thought on 
>>>>>> this seriously (becouse it took me a time to build this setup and 
>>>>>> see what is the  ground around that
>>>>>>
>>>>>> ship eventually also can make 'roll' moves and strafe moves 
>>>>>> (though im not sure those strafe moves i defined well, also by 
>>>>>> acceleration + dumping..it may be bad approach)
>>>>>>
>>>>>>
>>>>>> one of interesting tiny algorithm i tested it yet this
>>>>>>
>>>>>>
>>>>>>
>>>>>> void Patrol(int i,float3 *points,int point_count,float speed,float 
>>>>>> arrival_distance)
>>>>>> {
>>>>>>      if(!points || point_count<=0) return;
>>>>>>
>>>>>>      int point=(int)bag[i].mode;
>>>>>>
>>>>>>      if(point<0 || point>=point_count) point=0;
>>>>>>
>>>>>>      float3 destination=points[point];
>>>>>>      float3 direction=sub(destination,bag[i].p.pos);
>>>>>>
>>>>>>      if(length(direction)<arrival_distance)
>>>>>>      {
>>>>>>          point++;
>>>>>>          if(point>=point_count) point=0;
>>>>>>
>>>>>>          bag[i].mode=(unsigned)point;
>>>>>>          destination=points[point];
>>>>>>      }
>>>>>>
>>>>>>      FlyToward(i,destination,speed);
>>>>>> }
>>>>>>
>>>>>>
>>>>>> it just take array of 3d points and if near some then it turn to 
>>>>>> another and it in fact looks well...but i need some more
>>>>>
>>>>> For fun I closed my work and opened an old project of mine. Back 
>>>>> when I was experimenting with PBR:
>>>>>
>>>>> https://i.ibb.co/bM0vxPRV/image.png
>>>>>
>>>>> Btw, how are you drawing to the screen?
>>>>
>>>> windows has a blitter and you have normal buffer i ram
>>>>
>>>> unsigned* buf= NULL;
>>>>
>>>> whuch you then alloc and blit
>>>>
>>>> acces is buf[w*y+x] = color;
>>>>
>>>> but if some want not use winapi but some librery that allows to
>>>> use this cpu/ram buffers it will be just about the same thing
>>>> (assuing they wrote this libs sensible and they probably did)
>>>>
>>>
>>> Ahhh. Okay. Thanks. For learning, that's neat. Almost like you are 
>>> trying to build the pipeline directly on the CPU. Do you have a 
>>> pipeline? You should model at least vertex shader to frag shader.
>>
>> its much simpler than you think - its mainly triangle rasterization
>> routine (rasterizatio it is drawing with depth buffer also basic 
>> cliping).. light you can count using triangle normal and lights you 
>> define..
>>
>> one of  the main advantages it is just get know how simple it is and 
>> how it works..other advantage is in fact you can do what you want 
>> define thousand lights , defina routines for lightning like you want 
>> etc..try to think on rasterisation not triangles but bezier patches 
>> etc ..you can d what you want in pure c so its theretical freedom but 
>> ofc it will slow down
>>
>> more hard than basic rasterisation is maybe the transformation and 
>> projection by camera and camera movement as it needs imo a carefull 
>> understanding of x y z coordinates
>>
>> so this is kinda low level, simple transparent but you need to 
>> understand those few functions well..overally it also should be no 
>> point of focus more focus is higher layer of those ships and their 
>> interactions (which need some work, rasterization in turn is well known
>> and not really hard problem, well resolved and described)
>>
>>
>>
> 
> When you port over to say modern opengl, learning the raw pipeline might 
> help you out?

ofc it helps you a lot
Technical Details
Message-ID: <11drgcl$3sb4d$1@dont-email.me>
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <11dfm1u$3rhtq$1@dont-email.me> <11dongf$2tqf8$1@dont-email.me> <11dp02j$30b9k$1@dont-email.me> <11dqjqo$3kehp$2@dont-email.me> <11dqlqn$3l5dt$1@dont-email.me> <11dqo9p$3lp20$2@dont-email.me>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!srv.newsdeef.eu!news.hispagatos.org!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: fir <profesor.fir@gmail.com>
Newsgroups: comp.lang.c
Subject: Re: [p.i.c] ships flyin and faitin
Date: Sat, 21 Nov 2026 08:14:28 +0100
Organization: A noiseless patient Spider
Lines: 165
Message-ID: <11drgcl$3sb4d$1@dont-email.me>
References: <11dfm1u$3rhtq$1@dont-email.me> <11dongf$2tqf8$1@dont-email.me>
 <11dp02j$30b9k$1@dont-email.me> <11dqjqo$3kehp$2@dont-email.me>
 <11dqlqn$3l5dt$1@dont-email.me> <11dqo9p$3lp20$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 21 Nov 2026 07:14:30 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="4074637"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1/nKMq1qBuKP6mEfQaSzMIV0ZjnLIR08j0="; posting-host="75bdfe5f8f7f29b956273746f4003e1b"
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:140.0) Gecko/20100101
 Firefox/140.0 SeaMonkey/2.53.24
Cancel-Lock: sha1:hBnDthIGzqfroS+8UNCs+pfs/vA= sha256:kgv7ol+/eYDRLz2y/WDbZ8P0xnntskKq7B4naFzW/ds=
	sha1:jNTThfmOzaxWgWn74GoUjB8BfkI= sha256:zrQAlP6+SQ1PDUnRyUz5cRu7KdFFQ8hkN5e7F9KiR4E=
In-Reply-To: <11dqo9p$3lp20$2@dont-email.me>