November 21, 2019, 01:59:29 AM

Author Topic: Elite style movement help  (Read 843 times)

Offline JBR

  • Jr. Member
  • **
  • Posts: 35
Elite style movement help
« on: June 24, 2019, 07:12:28 PM »
Hi,

Left/Right moves around the z-axis but as soon as you do this the up/down around the x-axis does not look right. i.e. it is not up/down on screen.

Has anyone any ideas on how to get the rotation on screen and always up/down on screen as up/down movement.

I've done a Zarch/Virus game before where I combined rotation around the x-axis and then around z-axis and all worked as expected.

Any pointers?

Thanks, Jim.

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 253
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Elite style movement help
« Reply #1 on: June 25, 2019, 12:12:46 AM »
Wasnt Zarch rotation left/right around the y-axis, bank left/right around the z-axis and up/down on the x-axis?

*I'm playing the game in my head now, lol*

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Offline Qube

  • Administrator
  • Hero Member
  • *****
  • Posts: 2199
Re: Elite style movement help
« Reply #2 on: June 25, 2019, 06:00:32 AM »
Not quite sure what the issue is here but in 3D space if you're wanting true free 3D movement and rotation then using the common euler angles in many engines will cause a problem and you'll end up with what's known as gimbal lock which results in funky 3D rotations. For truly free 3D movement and rotations the mathematical method to use is via quaternion.

As said I'm not quite sure what your issue is and perhaps a code example demonstrating the problem would be helpful.

Quote
*I'm playing the game in my head now, lol*
Blast blast blast, yo!! look at those lovely fat square explosions ;D not that I've ever played it :P
Until the next time...

Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 820
Re: Elite style movement help
« Reply #3 on: June 25, 2019, 04:18:27 PM »
Gave up on my 3D space invaders meets asteroids due to funky 3D blips, wondering if gimbal lock was the issue now! :o

Offline JBR

  • Jr. Member
  • **
  • Posts: 35
Re: Elite style movement help
« Reply #4 on: June 25, 2019, 07:02:02 PM »
Hi, did a search and found https://www.syntaxbomb.com/index.php/topic,3176.msg4165.html#msg4165

Looks good.

Cheers guys, Jim.

Offline RemiD

  • Hero Member
  • *****
  • Posts: 1014
Re: Elite style movement help
« Reply #5 on: June 25, 2019, 08:48:32 PM »
if you look at the values returned by entitipitch, entityyaw, entityroll, you will realise that you can't really oriente an entity precisely between -180.0 and +180.0 on all axis, sometimes something is messed up...
so usually i forget about the roll and only use pitch and yaw to oriente on all possible orientations...
DualCore AMD E-450, 1646 MHz - 6 Go DDR3 1333 SDRAM - AMD Radeon HD 6320 Graphics (384 Mo) - Windows 7 Home Premium - DirectX 11.0

Offline JBR

  • Jr. Member
  • **
  • Posts: 35
Re: Elite style movement help
« Reply #6 on: June 26, 2019, 10:17:41 PM »
https://www.syntaxbomb.com/index.php/topic,3176.msg4165.html#msg4165

When I try and run this code there are 'funny' characters in it which buggers up compiling.

Most often is b*lip where * is like a square with a question mark.

It is on the actual listing so not my error. Help!

Jim

Offline Dabz

  • Sr. Member
  • ****
  • Posts: 253
  • Is it cos I is ginger?
    • dabzy.co.uk
Re: Elite style movement help
« Reply #7 on: June 27, 2019, 06:21:51 AM »
Its not you, copy and pasting buggers the formatting up

Dabz
Intel Core i5 6400 2.7GHz, NVIDIA GeForce GTX 1070 (8GB), 16Gig DDR4 RAM, 256GB SSD, 1TB HDD, Windows 10 64bit

Offline Krischan

  • Full Member
  • ***
  • Posts: 200
    • Krischan's Homepage
Re: Elite style movement help
« Reply #8 on: June 28, 2019, 09:51:32 AM »
On request here again the working code with executables in the attachment, looks as if something went wrong with the transfer of the code archive (the Blitz3D Types are incorrect).

The original code is still working:
Elite Style Scanner: http://www.mojolabs.nz/codearcs.php?code=2773
Elite Name Generator: http://www.mojolabs.nz/codearcs.php?code=2770

Oh, and for spaceship movement I've written this code years ago:

Code: BlitzBasic
  1. AppTitle "Infinite Starfield"
  2.  
  3. Graphics3D 800,600,32,2
  4.  
  5. Global SCALEX#          = 2.0                           ; starfield scale X
  6. Global SCALEY#          = 2.0                           ; starfield scale Y
  7. Global SCALEZ#          = 2.0                           ; starfield scale Z
  8.  
  9. Global TurnSpeed#       = 4.0                           ; cam turn speed
  10. Global RollSpeed#       = 0.5                           ; cam roll speed
  11. Global CameraSpeed#     = 0.01                          ; cam move speed
  12.  
  13. Global WIDTH%           = GraphicsWidth()       ; grab screen width
  14. Global HEIGHT%          = GraphicsHeight()      ; grab screen height
  15. Global TIMER%           = CreateTimer(60)       ; timer
  16.  
  17. Type star
  18.        
  19.         Field col%
  20.         Field x#,y#,z#
  21.        
  22. End Type
  23.  
  24. ; camera
  25. Global cam=CreateCamera()
  26. CameraRange cam,0.01,10
  27. PositionEntity cam,0,0,0
  28.  
  29. ; starfield mesh
  30. Global starfield=CreateMesh()
  31. Global surf=CreateSurface(starfield)
  32. Global star=CreateQuad()
  33. EntityTexture starfield,CreateStarTexture()
  34. EntityFX starfield,1+2+32
  35. EntityBlend starfield,3
  36.  
  37. ; add stars to starfield
  38. AddStars(20000,0.001,0.005)
  39.  
  40. MoveMouse WIDTH/2,HEIGHT/2
  41.  
  42. ; main loop
  43. While Not KeyHit(1)
  44.        
  45.         ; camera movement
  46.         Movement(cam)
  47.        
  48.         ; update stars
  49.         UpdateStarfield(cam,2,1)
  50.        
  51.         RenderWorld()
  52.        
  53.         WaitTimer TIMER
  54.        
  55.         Flip 0
  56.        
  57. Wend
  58.  
  59. End
  60.  
  61. ; create a simple star texture
  62. Function CreateStarTexture(size%=256,flags%=3)
  63.        
  64.         Local tex%=CreateTexture(size,size,flags)
  65.         Local tb%=TextureBuffer(tex)
  66.        
  67.         Local i#,j%,col%,rgb%
  68.        
  69.         SetBuffer tb
  70.         LockBuffer tb
  71.        
  72.         For j=0 To 255
  73.                
  74.                 col=255-j
  75.                 If col>255 Then col=255
  76.                 rgb=col*$1000000+col*$10000+col*$100+col
  77.                
  78.                 For i=0 To 360 Step 0.1
  79.                        
  80.                         WritePixelFast (size/2)+(Sin(i)*(j*size/512)),(size/2)+(Cos(i)*(j*size/512)),rgb,tb
  81.                        
  82.                 Next
  83.                
  84.         Next
  85.        
  86.         UnlockBuffer tb
  87.         SetBuffer BackBuffer()
  88.        
  89.         Return tex
  90.        
  91. End Function
  92.  
  93. ; rebuild starfield mesh
  94. Function UpdateStarfield(parent%,maxdist#=2.0,fade%=False)
  95.        
  96.         Local s.star,px#,py#,pz#,d#,a#
  97.        
  98.         ClearSurface(surf)
  99.        
  100.         For s.star = Each star
  101.                
  102.                 ; calc star position
  103.                 px=EntityX(parent)-s\x
  104.                 py=EntityY(parent)-s\y
  105.                 pz=EntityZ(parent)-s\z
  106.                
  107.                 ; check if star must be moved
  108.                 If px<-SCALEX Then s\x=s\x-(SCALEX*2)
  109.                 If px>+SCALEX Then s\x=s\x+(SCALEX*2)
  110.                 If py<-SCALEY Then s\y=s\y-(SCALEY*2)
  111.                 If py>+SCALEY Then s\y=s\y+(SCALEY*2)
  112.                 If pz<-SCALEZ Then s\z=s\z-(SCALEZ*2)
  113.                 If pz>+SCALEZ Then s\z=s\z+(SCALEZ*2)
  114.                
  115.                 ; reposition star
  116.                 PositionEntity star,s\x,s\y,s\z
  117.                
  118.                 ; star is visible?
  119.                 If EntityInView(star,cam) Then
  120.                        
  121.                         ; get distance
  122.                         d=EntityDistance(star,cam)
  123.                        
  124.                         ; check if not to far away
  125.                         If d<maxdist Then
  126.                                
  127.                                 ; align star to cam
  128.                                 PointEntity star,cam
  129.                                
  130.                                 ; add alpha
  131.                                 a=1.0 : If fade Then a=Normalize(d,maxdist*0.5,maxdist,1,0)
  132.                                
  133.                                 ; add star to starfield again
  134.                                 AddToSurface(star,surf,starfield,s\col,s\col,s\col,a)
  135.                                
  136.                         EndIf
  137.                        
  138.                 EndIf
  139.                
  140.         Next
  141.        
  142. End Function
  143.  
  144. ; add stars to starfield mesh
  145. Function AddStars(amount%=1,min#=0.01,max#=0.02)
  146.        
  147.         Local i%,s.star,size#
  148.        
  149.         For i=1 To amount
  150.                
  151.                 s.star = New star
  152.                
  153.                 size#=Rnd(min,max)
  154.                
  155.                 s\col=Rand(64,255)
  156.                 s\x=Rnd(-SCALEX,SCALEX)
  157.                 s\y=Rnd(-SCALEY,SCALEY)
  158.                 s\z=Rnd(-SCALEZ,SCALEZ)
  159.                
  160.                 PositionEntity(star,s\x,s\y,s\z,1)
  161.                 ScaleEntity star,size,size,size
  162.                 AddToSurface(star,surf,starfield,255,255,255,1)
  163.                
  164.         Next
  165.        
  166. End Function
  167.  
  168. ; simple spaceship freeflight
  169. Function Movement(cam%,sensitivity#=1.0)
  170.        
  171.         Local roll#,cx#,cz#,tx#,ty#
  172.        
  173.         cx=(KeyDown(205)-KeyDown(203))*CameraSpeed
  174.         cz=(KeyDown(200)-KeyDown(208))*CameraSpeed
  175.         roll=(MouseDown(2)-MouseDown(1))*RollSpeed
  176.        
  177.         tx=Normalize(MouseX(),0,WIDTH , 1,-1)
  178.         ty=Normalize(MouseY(),0,HEIGHT,-1, 1)
  179.        
  180.         If ty<0 Then ty=(Abs(ty)^sensitivity)*-1 Else ty=ty^sensitivity
  181.         If tx<0 Then tx=(Abs(tx)^sensitivity)*-1 Else tx=tx^sensitivity
  182.        
  183.         TurnEntity cam,ty*TurnSpeed,tx*TurnSpeed,roll*TurnSpeed
  184.         MoveEntity cam,cx,0,cz
  185.        
  186. End Function
  187.  
  188. ; normalize a value
  189. Function Normalize#(value#=128.0,value_min#=0.0,value_max#=255.0,norm_min#=0.0,norm_max#=1.0)
  190.        
  191.         Return ((value-value_min)/(value_max-value_min))*(norm_max-norm_min)+norm_min
  192.        
  193. End Function
  194.  
  195. ; add a mesh to another mesh's surface
  196. Function AddToSurface(mesh,surf,singlesurfaceentity,r%,g%,b%,a#)
  197.        
  198.         Local vert%[2],vr%[2],vg%[2],vb%[2],va#[2]
  199.         Local surface%,oldvert%,i%,i2%
  200.        
  201.         surface = GetSurface(mesh,1)
  202.        
  203.         For i = 0 To CountTriangles(surface)-1
  204.                
  205.                 For i2 = 0 To 2
  206.                        
  207.                         oldvert = TriangleVertex(surface,i,i2)
  208.                        
  209.                         vr[i2]=r
  210.                         vg[i2]=g
  211.                         vb[i2]=b
  212.                         va[i2]=a
  213.                        
  214.                         TFormPoint VertexX(surface,oldvert),VertexY(surface,oldvert),VertexZ(surface,oldvert), mesh,singlesurfaceentity
  215.                         vert[i2] = AddVertex(surf,TFormedX(),TFormedY(),TFormedZ(),VertexU(surface,oldvert),VertexV(surface,oldvert))
  216.                         VertexColor surf,vert[i2],r,g,b,a
  217.                        
  218.                 Next
  219.                
  220.                 AddTriangle(surf,vert[0],vert[1],vert[2])
  221.                
  222.         Next
  223.        
  224. End Function
  225.  
  226. ; create a quad
  227. Function CreateQuad(r%=255,g%=255,b%=255,a#=1.0)
  228.        
  229.         Local mesh%,surf%,v1%,v2%,v3%,v4%
  230.        
  231.         mesh=CreateMesh()
  232.         surf=CreateSurface(mesh)
  233.        
  234.         v1=AddVertex(surf,-1,1,0,1,0)
  235.         v2=AddVertex(surf,1,1,0,0,0)
  236.         v3=AddVertex(surf,-1,-1,0,1,1)
  237.         v4=AddVertex(surf,1,-1,0,0,1)
  238.        
  239.         VertexColor surf,v1,r,g,b,a
  240.         VertexColor surf,v3,r,g,b,a
  241.         VertexColor surf,v2,r,g,b,a
  242.         VertexColor surf,v4,r,g,b,a
  243.        
  244.         AddTriangle(surf,0,1,2)
  245.         AddTriangle(surf,3,2,1)
  246.        
  247.         FlipMesh mesh
  248.        
  249.         Return mesh
  250.        
  251. End Function
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline JBR

  • Jr. Member
  • **
  • Posts: 35
Re: Elite style movement help
« Reply #9 on: June 28, 2019, 07:23:55 PM »
Thankyou Krischan you are a diamond.

Jim.


Offline 3DzForMe

  • Hero Member
  • *****
  • Posts: 820
Re: Elite style movement help
« Reply #10 on: June 28, 2019, 09:29:00 PM »
Krishan, very generous what a star  ;D. I should be packing to go on holiday tomorrow, I can feel a go at Blitz3D coming on though....

Offline JBR

  • Jr. Member
  • **
  • Posts: 35
Re: Elite style movement help
« Reply #11 on: June 28, 2019, 10:17:19 PM »
I tried just the basic movement code with BMax and miniB3D and it performs not as expected.

I think they handle TurnEntity different.

Jim

Offline Krischan

  • Full Member
  • ***
  • Posts: 200
    • Krischan's Homepage
Re: Elite style movement help
« Reply #12 on: June 28, 2019, 10:21:07 PM »
Try the first Code (MiniB3D) in this thread in Blitzmax+MiniB3D, this is my latest spacegame movement code with Quaternion rotation. But I'm still not sure what you're looking for.

https://www.syntaxbomb.com/index.php/topic,5159.0.html
Kind regards
Krischan

Windows 10 Pro | i7 9700K@ 3.6GHz | RTX 2080 8GB]
My Blitzbasic Archive | Extrasolar Project | My Github projects

Offline JBR

  • Jr. Member
  • **
  • Posts: 35
Re: Elite style movement help
« Reply #13 on: June 29, 2019, 08:27:04 PM »
Hi Krischan,

Thanks again.

I think I'll be able to use a lot of your code, if that's ok.

TGlobal.EnableStates() in the End2D() gives the error Duplicate identifier 'tglobal' found in module 'm_minib3d' and module 'brl.reflection'.

I've just edited it out and everything works great. Not up on my GL stuff so hopefully no harm done.

My intention is to write an Elite style game, hopefully!

Jim.