[3D Programming] Ellement Cubes will not Delete, Help Need!

Everything related to 3D programming
User avatar
JamieVanCadsand
User
User
Posts: 34
Joined: Sun Jun 24, 2018 12:28 pm
Location: Holland

[3D Programming] Ellement Cubes will not Delete, Help Need!

Post by JamieVanCadsand »

Hey 3D Programmers and Game Developers...

Now i try to write an script, called to draw 3d rotated blocks into one stroke yet.
So this is my script, written in PB 5.6.2 on Windows XP:

Delete Cube Stroke, PB5.6.2 on Windows XP

Code: Select all

;****************************************************************************************************************
;Delete Cube Stroke (Rotated)
;****************************************************************************************************************

;Initializing
If InitEngine3D() = 0
  MessageRequester("Fatal Error", "Failed to Initialize Engine3D.dll", #PB_MessageRequester_Error)
  End
EndIf

If InitSprite() = 0
  MessageRequester("Fatal Error", "Failed to Initialize Sprites", #PB_MessageRequester_Error)
  End
EndIf

If InitKeyboard() = 0
  MessageRequester("Fatal Error", "Failed to Initialize Keyboard", #PB_MessageRequester_Error)
  End
EndIf

If OpenScreen(640, 480, 32, "", #PB_Screen_NoSynchronization) = 0
  MessageRequester("Fatal Error", "Failed to Open Screen", #PB_MessageRequester_Error)
  End
EndIf


;Call Variables and Enummerates
Declare Start3DWorld()

Global NewList Blocks.i()
Global Time.i = 4

Enumeration
  #Light_Dir
  #Light_Point1
  #Light_Point2
  
  #Player
  #Mesh
  #Entity
  #Node
EndEnumeration

;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************





;Starts 3D
Procedure Start3DWorld()
  
  CreateLight(#Light_Dir, RGB(255, 255, 200), 0, 0, 0, #PB_Light_Directional)
  CreateLight(#Light_Point1, RGB(255, 100, 100), 2, 1, 2, #PB_Light_Point)
  CreateLight(#Light_Point2, RGB(100, 255, 255), -2, -1, -2, #PB_Light_Point)
  
  CreateCamera(#Player, 0, 0, 100, 100)
  MoveCamera(#Player, 0, 0, 100)
  RotateCamera(#Player, 0, 0, 100)
  
  CreateCube(#Mesh, 1)
  CreateEntity(#Entity, MeshID(#Mesh), #PB_Material_None)
  
  CreateNode(#Node, 0, 0, 0)
  
  For I = 0 To 24 Step 2
    AddElement(Blocks())
    Blocks() = CopyEntity(#Entity, #PB_Any)
    MoveEntity(Blocks(), I, 0, 0, #PB_Absolute)
    AttachNodeObject(#Node, EntityID(Blocks()))
  Next I
  
  ExamineKeyboard()
  If KeyboardPushed(#PB_Key_Delete)
    DeleteElement(Blocks())
  EndIf
  
EndProcedure

;Render3D World and ask if player will be Exit this Program
Start3DWorld()
Repeat
  
  ExamineKeyboard()
  RotateNode(#Node, 1, 1, 1, #PB_Relative)
  RenderWorld()
  FlipBuffers()
  ClearScreen(0)
  
  If KeyboardPushed(#PB_Key_Escape)
    End
  EndIf
  
ForEver

;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;END Program
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
;****************************************************************************************************************
Now my goal is to learn how to program 3d, called the part to make 3d meshes deleteble (needed for the future of
my software yet)... If you press 'Delete', the cubes stroke must be deleted, but it doesn't... So look to this script,
to try see whats bad on my code, run this script and try to press the 'Delete Key' on the keyboard..., you will be
see thads the cubes don't will delete, just it don't works.

I get my cubes (Block Stroke) called into an AddElement(Blocks()) Function, but DeleteElement isn't works yet.
So pleace find whats bad on my code and if you see whats bad (but its not an error, just 'EnableExiplite' don't
should help such i think, its just an 'not working' whay the block stroke will not be delete if you press 'Delete Key'...),
pleace try to find the problem and correct my code yet..., just i can experiment with elements in 3d...

So Pleace correct my code and i hope its helps... Can you correct my code to fix this DeleteElement(Blocks()) Problem?,
Thanks for help, Jamie.
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: [3D Programming] Ellement Cubes will not Delete, Help Ne

Post by Mijikai »

It looks like you are only deleting one element
and the function is outside your main loop.
I suggest you take a look at the help-file.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: [3D Programming] Ellement Cubes will not Delete, Help Ne

Post by applePi »

use always a runnable code , so the users can test it and pinpoint the problem
there are 2 Delete keys the one on the Num keys called "Del" and the other one called "Delete"
using If KeyboardReleased(#PB_Key_Delete) will check the Delete key and not Del key
i have Flattened your code to make it easier to understand in one shot.
there is FreeEntity(Blocks()) .
check also HideEntity(Blocks(),1) which only hide the entity setting it to 0 the entity will appears again
use KeyboardPushed instead of KeyboardReleased to mass destruction of the cubes

Code: Select all

InitEngine3D()
InitSprite()
InitKeyboard()

Enumeration
  #Mesh
  #Entity
  #Node
EndEnumeration

OpenWindow(0, 0, 0, 800, 600, "Press DELETE key (not Del) to remove Entities ... ,Press ESC To exit", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, 800, 600)

CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0, 0, 20, 25)
CameraLookAt(0, 0,0,0)
;CameraRenderMode(0, #PB_Camera_Wireframe)

;CreateLight(#Light, Color [, x, y, z [, Flags]])
CreateLight(1, RGB(220,20,120), 0,100,20)


CreateCube(#Mesh, 0.8)
CreateEntity(#Entity, MeshID(#Mesh), #PB_Material_None)
  
CreateNode(#Node, 0, 0, 0)

Global NewList Blocks.i()
Global Time.i = 4
  Radius.f = 10
  For I = 0 To 23
    AddElement(Blocks())
    Blocks() = CopyEntity(#Entity, #PB_Any)
    angle.f + #PI*2/24
    x.f=Cos(angle)*Radius
    z.f=Sin(angle)*Radius
       
    MoveEntity(Blocks(), x, 0, z, #PB_Absolute)
    AttachNodeObject(#Node, EntityID(Blocks()))
  Next I


Repeat
    Repeat
    event = WindowEvent()
  Until event = 0
  
  ExamineKeyboard()
  ;If KeyboardPushed(#PB_Key_Delete)
  If KeyboardReleased(#PB_Key_Delete)  
    num + 1
    If num > 24
      SetWindowTitle(0, "Sorry no other entities to delete, Press ESC to exit"):Goto jump
    EndIf
    ;HideEntity(Blocks(),1)
    FreeEntity(Blocks())
    DeleteElement(Blocks())
  EndIf
  
  jump: 
  RenderWorld()
  
  FlipBuffers()
  
  ExamineKeyboard()
  
Until  KeyboardReleased(#PB_Key_Escape)
Post Reply