Page 2 of 3

Re: Something beautiful...

Posted: Sat Aug 16, 2014 9:05 am
by DK_PETER
@applePi
Thanks for the feedback. Yes..The initial rotational value should be a little higher and it will be. ;-)

@PB

You might need to initialize keyboard, mouse etc.. from inside the module instead of the outside...
Try this:

Code: Select all

;It has absolutely no real value,
;but I think, that it looks good and I certainly enjoy these things...
;(Title: A world inside an entity)
;By Peter Bach - DK_PETER
;Keys 1-9 and Q-Y changes shapes
;Arrow keys to move
;(Continue pressing an arrow key either increases Or decreases speed) - release arrow key means full stop
; + and - to change rotational speed of entity
;Enjoy...

DeclareModule _Patterns
  Declare.i DoScreen(Width.i = 1024, Height.i = 768)
  Declare.i BeginJoy()
  Declare.i Init()
EndDeclareModule

Module _Patterns
  Structure _mesh
    id.i
    ms.i
    tx.i
    mt.i
  EndStructure
 
  Structure vector3D
    x.f
    y.f
    z.f
  EndStructure
 
  Declare.i Calc(*ReturnVec.Vector3D, CenterX.f, CenterY.f, CenterZ.f, AngleX.f, AngleY.f, RadiusX.i, RadiusY.i, RadiusZ.i )
  Global ms._mesh, cam.i, v.vector3D, rotaspeed.f = 0.01, keyx.f = 0.0, keyy.f = 0.0
 
  Procedure.i DoScreen(Width.i = 1024, Height.i = 768)
    OpenWindow(0, 0, 0, Width, Height, "I truly enjoy Ogre3D", #PB_Window_ScreenCentered)
    OpenWindowedScreen(WindowID(0), 0, 0, Width, Height,0, 0, 0, #PB_Screen_SmartSynchronization)
    cam = CreateCamera(#PB_Any, 0, 0, 100, 100)
    MoveCamera(cam, 0, 0, 800)
  EndProcedure
  
  Procedure.i Init()
    DisableDebugger
    InitEngine3D()
    InitSprite()
    InitKeyboard()
    InitMouse()
  EndProcedure

  Procedure.i Createsomething(Index.i = 0)
    MoveCamera(cam, 0, 0, 800, #PB_Absolute)  ;<---#PB_Absolute (forgot the constant)
    CameraLookAt(cam, 0, 0, 0)
    If IsEntity(ms\id) > 0
      FreeEntity(ms\id)
      FreeMaterial(ms\mt)
      FreeTexture(ms\tx)
      FreeMesh(ms\ms)
    EndIf
   
    ms\ms = CreateMesh(#PB_Any, #PB_Mesh_PointList,#PB_Mesh_Dynamic)
    v\x = 0: v\y = 0: v\z = 0
    For x = 0 To 1000
      For y = 0 To 1000
        Select Index
          Case 0
            Calc(v, 0, 0, 0, x, y, x, x, y)
            MeshVertexPosition(v\x , v\y, v\z)
          Case 1
            Calc(v, 0, 0, 0, x, y , x*Tan(Cos(y)),  Random(100), x-1 )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 2
            Calc(v, 0, 0, 0, Random(360), Random(360), x,  Random(400), x )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 3
            Calc(v, 0, 0, 0, x*0.3, y*0.4 , x*0.2,  Random(100), x )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 4
            Calc(v, 0, x, 0, x*Sqr(y), y*Sin(y) , x*Cos(x),  Random(700), x )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 5
            Calc(v, 0, 0, 0, Random(180), Random(180) , x + Random(20),  x + Random(20), y + Random(20))
            MeshVertexPosition(v\x , v\y, v\z)
          Case 6
            Calc(v, 0, 0, 0, (x+1) / 0.6, (y+2)/0.4 , x ,  y , x)
            MeshVertexPosition(v\x , v\y, v\z)
          Case 7
            Calc(v, 0, 0, 0, x, y , x,  Random(100), x )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 8
            Calc(v, 0, 0, 0, Random(60), y , x+Random(100),  Random(100), x + Random(100) )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 9
            Calc(v, (Random(15,1)/0.3), (Random(15,1)/0.3), (Random(15,1)/0.3), Random(90), Random(90) , x+Random(100),  x + Random(100), x + Random(100) )
            MeshVertexPosition(v\x, v\y, v\z)
          Case 10
            Calc(v, 0, 0, 0, x * 0.3, y * 0.2, x, x, y)
            MeshVertexPosition(v\x , v\y, v\z)
          Case 11
            Calc(v, 0, 0, 0, x , y , x, x, x )
            MeshVertexPosition(v\x , v\y , v\z)
          Case 12
            Calc(v, 0, 0, 0, x, y , x*Tan(Cos(y)),  y*Tan(Sin(x)), x-1 )
            MeshVertexPosition(v\x , v\y, v\z)
          Case 13
            Calc(v, 0, 0, 0, x, y , x*Tan(Cos(y)),  y*Tan(Sin(x)), x*Tan(Cos(y)))
            MeshVertexPosition(v\x , v\y, v\z)
          Case 14
            Calc(v, 0, 0, 0, Radian(x), Radian(y) , x*Tan(Sin(y)),  y*Tan(Cos(x)), x*Tan(Sin(y)))
            MeshVertexPosition(v\x , v\y, v\z)
        EndSelect
      Next y
    Next x
    NormalizeMesh(ms\ms)
    FinishMesh(#True)
   
    ms\tx = CreateTexture(#PB_Any, 256, 256)
    StartDrawing(TextureOutput(ms\tx))
    DrawingMode(#PB_2DDrawing_Gradient)
    FrontColor(RGB(Random(255,50),Random(255,50),Random(255,50)))
    BackColor(RGB(Random(255,50),Random(255,50),Random(255,50)))
    BoxedGradient(0,0,256,256)
    Box(0,0,256,256)
    StopDrawing()
    ms\mt = CreateMaterial(#PB_Any, TextureID(ms\tx))
    MaterialBlendingMode(ms\mt,#PB_Material_Add)
    ms\id = CreateEntity(#PB_Any, MeshID(ms\ms),MaterialID(ms\mt))
  EndProcedure
 
  Procedure.i BeginJoy()
    Createsomething(0)
   
    Repeat
      Repeat: ev=WindowEvent():Until ev=0
      RotateEntity(ms\id, rotaspeed, rotaspeed, rotaspeed, #PB_Relative)
      ExamineMouse()
      RotateCamera(cam, -MouseDeltaY()*0.05, -MouseDeltaX()*0.05, 0, #PB_Relative)
      RenderWorld()
      ExamineKeyboard()
      If KeyboardReleased(#PB_Key_1)
        Createsomething(0)
      ElseIf KeyboardReleased(#PB_Key_2)
        Createsomething(1)
      ElseIf KeyboardReleased(#PB_Key_3)
        Createsomething(2)
      ElseIf KeyboardReleased(#PB_Key_4)
        Createsomething(3)
      ElseIf KeyboardReleased(#PB_Key_5)
        Createsomething(4)
      ElseIf KeyboardReleased(#PB_Key_6)
        Createsomething(5)
      ElseIf KeyboardReleased(#PB_Key_7)
        Createsomething(6)
      ElseIf KeyboardReleased(#PB_Key_8)
        Createsomething(7)
      ElseIf KeyboardReleased(#PB_Key_9)
        Createsomething(8)
      ElseIf KeyboardReleased(#PB_Key_Q)
        Createsomething(9)
      ElseIf KeyboardReleased(#PB_Key_W)
        Createsomething(10)
      ElseIf KeyboardReleased(#PB_Key_E)
        Createsomething(11)
      ElseIf KeyboardReleased(#PB_Key_R)
        Createsomething(12)
      ElseIf KeyboardReleased(#PB_Key_T)
        Createsomething(13)
      ElseIf KeyboardReleased(#PB_Key_Y)
        Createsomething(14)
      EndIf
      If KeyboardPushed(#PB_Key_Add)
        rotaspeed + 0.01
      EndIf
      If KeyboardPushed(#PB_Key_Subtract)
        rotaspeed - 0.01
      EndIf
     
      If KeyboardPushed(#PB_Key_Left)
        keyx - 0.1
      ElseIf KeyboardPushed(#PB_Key_Right)
        keyx + 0.1
      Else
        keyx = 0
      EndIf
      If KeyboardPushed(#PB_Key_Up)
        keyy - 0.1
      ElseIf KeyboardPushed(#PB_Key_Down)
        keyy + 0.1
      Else
        keyy = 0
      EndIf
      MoveCamera(cam, keyx, 0, keyy)
     
      FlipBuffers()
     
    Until KeyboardPushed(#PB_Key_Escape)
    End
  EndProcedure
 
  Procedure.i Calc(*ReturnVec.Vector3D, CenterX.f, CenterY.f, CenterZ.f, AngleX.f, AngleY.f, RadiusX.i, RadiusY.i, RadiusZ.i )
    *ReturnVec\X = CenterX + RadiusX*Cos(AngleY)*Cos(AngleX)
    *ReturnVec\Y = CenterY + RadiusY*Sin(AngleX)
    *ReturnVec\Z = CenterZ + RadiusZ*Sin(AngleY)*Cos(AngleX)
  EndProcedure
 
EndModule

_Patterns::Init()
_Patterns::DoScreen()
_Patterns::BeginJoy()

Re: Something beautiful...

Posted: Sat Aug 16, 2014 1:11 pm
by PB
Thanks for explaining.

Re: Something beautiful...

Posted: Sat Aug 16, 2014 9:58 pm
by LuCiFeR[SD]
It's not very often I praise peoples work.... but on this occasion DK_PETER... thats awesome :)

Re: Something beautiful...

Posted: Sun Aug 17, 2014 11:49 am
by Crusiatus Black
Absolutely beautiful! Great work!

Re: Something beautiful...

Posted: Sun Aug 17, 2014 2:04 pm
by DK_PETER
Thanks guys :-)

Again...Anyone interested in testing Beta 2 of my "something beautiful?
Added a lot of new things to it.
Note: The final release won't use keys to shift between patterns.

Links will be available until monday and taken down again the same day..

What I need is feedback!!
Smoothness and the general flow of things.
Your hardware specs: if thing are running like an 95 old man behind the wheels:
(No offence intended - If we got one in this forum) :lol:

*moved to first post...

Thank you in advance for your help.

Re: Something beautiful...

Posted: Sun Aug 17, 2014 3:47 pm
by applePi
1- in 800x600 (which are my default res) the buttons to choose resolution and the "Apply" are too much at the bottom of the window, i can see part of it when draging the window up.
Image
may be using the purebasic DesktopHeight() and DesktopHeight() will be more convenient without letting the user to choose other than his resolution, so every one gets whats suitable for his resolution automatically.
2- also the graphics are not in the center of the screen but to the left/bottom so we need to move the mouse to center the graphics.
3- the flow are good and i don't see sluggish performance
4- my spec. is desktop windows xp. cpu i5-2500. 3.23 GB of ram. Geforce GT 520, monitor Led 22"
5- some graphics are not centered rotated but rotating with some orbit, may be using mesh centering will be usefull look here http://purebasic.fr/english/viewtopic.p ... 3e#p417662
and here for automatically centering a mesh
http://purebasic.fr/english/viewtopic.p ... 3e#p417666
but in some cases a small orbit will be good, thats depends on the graphics

6- i will try on a very old laptop later (without a dedicated graphics card) since it may needs to install DX

Re: Something beautiful...

Posted: Sun Aug 17, 2014 3:53 pm
by DK_PETER
@applePi
Yes. I noticed the buttons were too much at the bottom at very low resolution.
I'll change that and make sure that it'll fit no matter the resolution.
Concerning the objects: I know, that some of the are off center.
This will be changed in next version.

Thank you for your specs.

Re: Something beautiful...

Posted: Sun Aug 17, 2014 4:46 pm
by DK_PETER
@applePi.
Screen settings should work now - even at lowest resolution.
Object should now be centered.

Links are moved to first post.

Re: Something beautiful...

Posted: Sun Aug 17, 2014 5:50 pm
by applePi
DK_PETER , now the graphics are centered. still some notes
the buttons are like before bellow the bottom in res 800x600. you need to raise it slightly.

F10 :it does not load a new scene until i press it again

M : the graphics are too slow even i find difficulty in moving it by mouse and it is at the right of the screen (not centered). but strangely it is much speedier on windows 7 on the same pc , so then i can see it is like a cube. of course win7 are more optimized for modern hardware.

6 and 7: needs to be centered

also for some consecutive scenes they are all rotating in the same direction. it is preferred that if this rotate to the right then the next one rotates to the left either in random or designed orientation.

Re: Something beautiful...

Posted: Sun Aug 17, 2014 6:05 pm
by DK_PETER
applePi wrote:DK_PETER , now the graphics are centered. still some notes
the buttons are like before bellow the bottom in res 800x600. you need to raise it slightly.

F10 :it does not load a new scene until i press it again

M : the graphics are too slow even i find difficulty in moving it by mouse and it is at the right of the screen (not centered). but strangely it is much speedier on windows 7 on the same pc , so then i can see it is like a cube. of course win7 are more optimized for modern hardware.

6 and 7: needs to be centered

also for some consecutive scenes they are all rotating in the same direction. it is preferred that if this rotate to the right then the next one rotates to the left either in random or designed orientation.
The setup is fixed now.
F10 is weird..I think this function key is waiting for something else. It continues without a hitch by (as you stated) by pressing f10 again or pressing the mouse button.
It's not important, though. None of the keys will be used in the final version.
6 and 7 are centered now....Wrong constant used :-)
M is as you said the cube. It's centered now.

I'll update the beta in a moment.

Thank you for your testing. I truly appreciate the time you're spending on this.

Re: Something beautiful...

Posted: Sun Aug 17, 2014 6:12 pm
by DK_PETER
Links in first post updated...

Re: Something beautiful...

Posted: Mon Aug 18, 2014 7:01 am
by Crusiatus Black
It runs extremely smoothly on my laptop; i7 4500u @1.8 - 2.4 GHz, 16 GiB RAM and a AMD Radeon HD8670M. 1366x768 @60

I would love to see the source code to this, the first version of the code was very educational. I don't often
render to a screen, especially not when rendering a world with skydome/box. How did you draw transparent
text over the output?

Great work, cheers!

Re: Something beautiful...

Posted: Mon Aug 18, 2014 10:12 am
by DK_PETER
Crusiatus Black wrote:It runs extremely smoothly on my laptop; i7 4500u @1.8 - 2.4 GHz, 16 GiB RAM and a AMD Radeon HD8670M. 1366x768 @60

I would love to see the source code to this, the first version of the code was very educational. I don't often
render to a screen, especially not when rendering a world with skydome/box. How did you draw transparent
text over the output?

Great work, cheers!
Edit: Transparent text is done using sprites. (question eluded my eyes).
Thank you for your info. Concerning the code...I'll think about it. ;-)

To all:
I think the program is almost as I want it now.
The navigational panel needs some special gfx attention, so I'm gonna use some time designing and
add a lot of extra math.
See first post, if you wish to play with it. Links are available until wednesday.
Enjoy.

Re: Something beautiful...

Posted: Mon Aug 18, 2014 2:43 pm
by Crusiatus Black
DK_PETER wrote:Edit: Transparent text is done using sprites. (question eluded my eyes).
Thank you for your info. Concerning the code...I'll think about it. ;-)
Would you be able to share a little piece of code showing me how I can do that with sprites? I attempted it with sprites, with the #PB_Sprite_AlphaBlending flag, then I display the sprite with DisplayTransparentSprite. However, I can't seem to get it right with the sprite background color. It's always black for me.

Re: Something beautiful...

Posted: Mon Aug 18, 2014 4:26 pm
by DK_PETER
Crusiatus Black wrote: Would you be able to share a little piece of code showing me how I can do that with sprites? I attempted it with sprites, with the #PB_Sprite_AlphaBlending flag, then I display the sprite with DisplayTransparentSprite. However, I can't seem to get it right with the sprite background color. It's always black for me.
Hope this helps:

Code: Select all

InitSprite()
InitKeyboard()

Global bg.i, sp.i, Quit.i = 0
OpenWindow(0, 0, 0, 1024, 768, "Sprite",#PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768, 0, 0, 0,#PB_Screen_SmartSynchronization)

bg = CreateImage(#PB_Any, 1024, 768, 32)
StartDrawing(ImageOutput(bg))
DrawingMode(#PB_2DDrawing_Gradient)
FrontColor($E10007)
BackColor($E100FF)
BoxedGradient(0, 0, 1024, 768)
Box(0, 0, 1024, 768)
StopDrawing()

sp = CreateSprite(#PB_Any, 200, 50)
StartDrawing(SpriteOutput(sp))
DrawingMode(#PB_2DDrawing_Transparent)
DrawText(10,10,"TESTING THE TEXT", $020003)
StopDrawing()


Repeat
  
  StartDrawing(ScreenOutput())
  DrawImage(ImageID(bg),0,0)
  StopDrawing()
  
  Repeat
    ev = WindowEvent()
    If ev = #PB_Event_CloseWindow
      Quit = 1
    EndIf
  Until ev = 0
  
  DisplayTransparentSprite(sp, ScreenWidth()/2-100,ScreenHeight()/2-25, 160) 
  ExamineKeyboard()
  
  FlipBuffers()
  
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1