[SOLVED] - [PB5.50] CreateCone : IMA

Everything related to 3D programming
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

[SOLVED] - [PB5.50] CreateCone : IMA

Post by falsam »

I have an IMA with this test code.

Code: Select all

EnableExplicit

Structure NewEntity
  Primitive.s
  Mesh.i  
EndStructure
Global NewMap Entities.NewEntity() 

Global event

Declare AddPrimitive(Primitive.s, x.f, y.f, z.f)

InitEngine3D() : InitKeyboard() : InitSprite()

OpenWindow(0, 0, 0, 1024, 768, "Test")
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)

CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(245, 222, 179))
MoveCamera(0, 0, 5, 10)
CameraLookAt(0, 0, 0, 0)
CreateLight(0, RGB(255, 255, 255), -100, 200, 100)

;Test here
AddPrimitive("sphere", -2, 0, 0) 
AddPrimitive("cube", 2, 0, 0) 
;AddPrimitive("cone", 0, 0, 0) 


While #True  
  Repeat
    Event  = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0     
  
  If ExamineKeyboard()  
    If KeyboardReleased(#PB_Key_Escape)
      Break
    EndIf    
  EndIf
  
  RenderWorld()
  FlipBuffers()
Wend

Procedure AddPrimitive(Primitive.s, x.f, y.f, z.f)
  Protected Index = MapSize(Entities()) + 1
  
  AddMapElement(Entities(), Str(Index)) 
  Entities()\Primitive = Primitive
  Select Primitive
    Case "cube"
      Entities()\Mesh = CreateCube(-1, 1)
      CreateEntity(Index, MeshID(Entities()\Mesh), #PB_Material_None, x, y, z)
            
    Case "cone"
      Entities()\Mesh = CreateCone(-1, 0.5, 1)
      CreateEntity(Index, MeshID(Entities()\Mesh), #PB_Material_None, x, y, z)
      
    Case "sphere"
      Entities()\Mesh = CreateSphere(-1, 1)
      CreateEntity(Index, MeshID(Entities()\Mesh), #PB_Material_None, x, y, z)
           
  EndSelect   
EndProcedure
■ If you un-comment line 27, you have this error
Debug wrote:[ERROR] Line: 61
[17:54:07] [ERROR] #Entity object number is very high (over 100000), are You sure of that ?
■ Now Comment line 61. You have this error
Debug wrote:[ERROR] Invalid memory access. (Read error at address 0)
I do not understand and I need help. Thank you.
Last edited by falsam on Sat Oct 15, 2016 9:59 am, edited 2 times in total.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: CreateCone : IMA

Post by DK_PETER »

Personally, I wouldn't use Map() - I rather use the NewList() or Array().

The IMA for Cone is related to the last two parameters. (Old versions of PB 5.42/5.43)

Here's your example (fixed and with list()):

Code: Select all

EnableExplicit

Structure NewEntity
  Primitive.s
  Mesh.i 
  ent.i
EndStructure

Global NewList Entities.NewEntity()

Global event, Elap.i, Count = 0

Declare AddPrimitive(Primitive.s, x.f, y.f, z.f)

InitEngine3D() : InitKeyboard() : InitSprite()

OpenWindow(0, 0, 0, 1024, 768, "Test")
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)

CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(245, 222, 179))
MoveCamera(0, 0, 5, 10)
CameraLookAt(0, 0, 0, 0)
CreateLight(0, RGB(255, 255, 255), -100, 200, 100)

;Test here
AddPrimitive("sphere", -2, 0, 0)
AddPrimitive("cube", 2, 0, 0)
AddPrimitive("cone", 0, 0, 0)


While #True 
  Repeat
    Event  = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0     
 
  If ExamineKeyboard() 
    If KeyboardReleased(#PB_Key_Escape)
      Break
    EndIf   
  EndIf
  If ElapsedMilliseconds() - Elap > 2000
    If Count = ListSize(Entities())-1
      Count = 0
    Else
      Count + 1
    EndIf
    SelectElement(Entities(), Count)
    Elap = ElapsedMilliseconds()
  EndIf
  
  RotateEntity(Entities()\ent, 0.4, -1, 1, #PB_Relative)
  
  RenderWorld()
  FlipBuffers()
Wend

Procedure AddPrimitive(Primitive.s, x.f, y.f, z.f)
  Protected Index = ListSize(Entities()) + 1
 
  AddElement(Entities())
  Entities()\Primitive = Primitive
  Select Primitive
    Case "cube"
      Entities()\Mesh = CreateCube(#PB_Any, 1)
      Entities()\ent = CreateEntity(#PB_Any, MeshID(Entities()\Mesh), #PB_Material_None, x, y, z)
           
    Case "cone"
      Entities()\Mesh = CreateCone(#PB_Any, 0.5, 1, 16, 16)  ;<-- old 5.42/5.43 problem..Fixed in 5.50.
      Entities()\ent = CreateEntity(#PB_Any, MeshID(Entities()\Mesh), #PB_Material_None, x, y, z)
     
    Case "sphere"
      Entities()\Mesh = CreateSphere(#PB_Any, 1)
      Entities()\ent = CreateEntity(#PB_Any, MeshID(Entities()\Mesh), #PB_Material_None, x, y, z)
           
  EndSelect   
EndProcedure
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
infratec
Always Here
Always Here
Posts: 7699
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CreateCone : IMA

Post by infratec »

Hm...

CreateEntity() expects .i as coordinates and not .f
It works also with the map.

I'm using 5.50 x86 and still have the same problem.
,16, 1
is still the fix.

Bernd
User avatar
DK_PETER
Addict
Addict
Posts: 904
Joined: Sat Feb 19, 2011 10:06 am
Location: Denmark
Contact:

Re: CreateCone : IMA

Post by DK_PETER »

infratec wrote:Hm...

CreateEntity() expects .i as coordinates and not .f
It works also with the map.

I'm using 5.50 x86 and still have the same problem.
,16, 1
is still the fix.

Bernd
CreateEntity expects floats as coordinate in 3D space.

Yes...Map() works. But I prefer List() or Array().. It's a matter of preference.

You're right..In PB 5.50 X86 the problem persist. Last parameters of cone must be added.
Fixed in PB 5.50 X64.
Current configurations:
Ubuntu 20.04/64 bit - Window 10 64 bit
Intel 6800K, GeForce Gtx 1060, 32 gb ram.
Amd Ryzen 9 5950X, GeForce 3070, 128 gb ram.
infratec
Always Here
Always Here
Posts: 7699
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: CreateCone : IMA

Post by infratec »

DK_PETER wrote:CreateEntity expects floats as coordinate in 3D space.
Then, at least, the help should be extended.
Because there is nothing written about that.
The parameters has not type specified, so it looks like .i

Bernd
User avatar
falsam
Enthusiast
Enthusiast
Posts: 635
Joined: Wed Sep 21, 2011 9:11 am
Location: France
Contact:

Re: [PB5.50] CreateCone : IMA

Post by falsam »

DK_PETER, infratec thank you for your replies.
DK_PETER wrote:The IMA for Cone is related to the last two parameters. (Old versions of PB 5.42/5.43)

Code: Select all

CreateCone(#PB_Any, 0.5, 1, 16, 16)
Infratec wrote:I'm using 5.50 x86 and still have the same problem.
Yes same problem with my procedure.

But this is correct without procedure. Needless to add the last two parameters with PB 5.50. Strange !

Code: Select all

EnableExplicit

Global event

InitEngine3D() : InitKeyboard() : InitSprite()

OpenWindow(0, 0, 0, 1024, 768, "Test")
OpenWindowedScreen(WindowID(0), 0, 0, 1024, 768)

CreateCamera(0, 0, 0, 100, 100)
CameraBackColor(0, RGB(245, 222, 179))
MoveCamera(0, 0, 5, 10)
CameraLookAt(0, 0, 0, 0)
CreateLight(0, RGB(255, 255, 255), -100, 200, 100)

;Test here
CreateSphere(0, 1)
CreateEntity(0, MeshID(0), #PB_Material_None, -2, 0, 0)

CreateCube(1, 1)
CreateEntity(1, MeshID(1), #PB_Material_None, 2, 0, 0)

CreateCone(2, 0.5, 1) ;<-- Needless to add the last two parameters.
CreateEntity(2, MeshID(2), #PB_Material_None, 0, 0, 0)

While #True  
  Repeat
    Event  = WindowEvent()
    Select Event
      Case #PB_Event_CloseWindow
        End
    EndSelect
  Until Event = 0     
  
  If ExamineKeyboard()  
    If KeyboardReleased(#PB_Key_Escape)
      Break
    EndIf    
  EndIf
  
  RenderWorld()
  FlipBuffers()
Wend
In any case. Thank you for your help, I can continue my code.

➽ Windows 11 64-bit - PB 6.21 x64 - AMD Ryzen 7 - NVIDIA GeForce GTX 1650 Ti

Sorry for my bad english and the Dunning–Kruger effect 🤪
Post Reply