3D challenge for a special rotation

Everything related to 3D programming
Realizimo
User
User
Posts: 71
Joined: Sun Nov 25, 2012 5:27 pm
Location: Sweden

Re: 3D challenge for a special rotation

Post by Realizimo »

my contribution

Code: Select all

EnableExplicit
#Camara = 3
#Entity = 3
#node= 3
#Light = 3
#Texture = 3 
#Material = 3
#Mesh = 3

If ExamineDesktops()=0 : End : EndIf
Global bitplanes.a=DesktopDepth(0)
Global FRX.u=DesktopWidth(0)*0.9
Global FRY.u=DesktopHeight(0)*0.9

If InitEngine3D(#PB_Engine3D_NoLog,#PB_Compiler_Home+"Compilers\Engine3d.dll")=0
  MessageRequester("Error","The 3D Engine can't be initialized",0)
  End
EndIf
InitSprite()
InitKeyboard()
InitMouse()
OpenWindow(0,0,0,FRX,FRY,"special rotation",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,FRX,FRY,1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home+"examples/3D/Data/Packs/skybox.zip",#PB_3DArchive_Zip)
SkyBox("stevecube.jpg")
CreateLight(#Light,$EEEEEE,4,4,2,#PB_Light_Point)
CreateCamera(#Camara,0,0,100,100)
CreateNode(#node,0,0,0)
CameraRange(#Camara,0.1,10000)
CameraBackColor(#Camara,$181911)
MoveCamera(#Camara,0,0,6,#PB_Absolute)
If CreateTexture(#Texture,32,32)
  Global Font.i=LoadFont(#PB_Any,"Arial",8)
  StartDrawing(TextureOutput(#Texture))
  Box(0,0,16,16,RGB(255,0,0))
  Box(16,0,16,16,RGB(0,255,0))
  Box(0,16,16,16,RGB(0,0,255))
  Box(16,16,16,16,RGB(255,255,0))
  DrawingFont(FontID(Font))
  DrawingMode(#PB_2DDrawing_Transparent)
  DrawText(5,3,"Hello",RGB(0,0,0))
  DrawText(2,15,"World",RGB(0,0,0))
  StopDrawing()
EndIf
CreateNode(#node,0,0,0)
CreateMaterial(#material,TextureID(#Texture))
CreateCube(#Mesh,1)
CreateEntity(#Entity,MeshID(#Mesh),MaterialID(#material))

Global.f mdx,mdy,mdz,THETA
Global.b lmb,rmb,mmb
#speed=0.01
Repeat
  While WindowEvent() : Wend
  ExamineMouse()
  ExamineKeyboard()
;   lmb=MouseButton(#PB_MouseButton_Left)
  rmb=MouseButton(#PB_MouseButton_Right)
;   mmb=MouseButton(#PB_MouseButton_Middle)
  mdx=MouseDeltaX()*#speed
  mdy=MouseDeltaY()*#speed
  mdz=MouseWheel()*#speed
  If KeyboardPushed(#PB_Key_F5)
    RotateEntity(#Entity, 0,0,0)
    MoveNode(#node,0,0,0, #PB_Absolute)
  ElseIf rmb
    MoveNode(#node , mdx , -mdy , -mdz*30)    
  Else    
    DetachNodeObject(#node, EntityID(#Entity)) 
    MoveEntity      (#Entity,0,0,0,#PB_Absolute)
    AttachNodeObject(#node, EntityID(#Entity))
    RotateNode      (#node, mdy*10 , mdx*10 , mdz*300)
  EndIf
  RenderWorld()
  FlipBuffers()  
Until KeyboardPushed(#PB_Key_Escape)
User avatar
Psychophanta
Always Here
Always Here
Posts: 5153
Joined: Wed Jun 11, 2003 9:33 pm
Location: Anare
Contact:

Re: 3D challenge for a special rotation

Post by Psychophanta »

You do not even move de camera. It is evident you have not catched the point of this; i am not able to explain it better than the first tip posted in my last post.

[202404171750]
Wow, one really never stops learning; The thing was much simpler to do:

Code: Select all

InitEngine3D(#PB_Engine3D_NoLog,#PB_Compiler_Home+"Compilers\Engine3d.dll")
InitSprite():InitKeyboard():InitMouse()
OpenWindow(0,0,0,800,600,"tip",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,800,600,0,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/Textures", #PB_3DArchive_FileSystem)
Add3DArchive(#PB_Compiler_Home + "examples/3d/Data/fonts", #PB_3DArchive_FileSystem)
Parse3DScripts()
CreateLight(0,$EEEEEE,4,4,2,#PB_Light_Point)
CreateCamera(0,0,0,100,100):CameraProjectionMode(0,#PB_Camera_Perspective)
MoveCamera(0,0,0,3,#PB_Absolute)
CreateMaterial(0,0,$33EEEE)
CreateMaterial(1,LoadTexture(1,"soil_wall.jpg"))

CreateCylinder(0,0.025,2):TransformMesh(0,0,0,0,1,1,1,90,0,0)
CreateText3D(0,"incl","",0.2,$8899FAFA):MoveText3D(0,-1.2,0,0)
CreateCube(1,0.5)
CreateEntity(0,MeshID(0),MaterialID(0),0,0,0):RotateEntity(0,90,0,0)
CreateEntity(1,MeshID(1),MaterialID(1),0,0,0)

Repeat
  While WindowEvent():Wend
  ExamineMouse():ExamineKeyboard()
  CursorX.f=MouseX():CursorY.f=MouseY():lmb.b=MouseButton(#PB_MouseButton_Left):rmb.b=MouseButton(#PB_MouseButton_Right)
  mdx.f=MouseDeltaX()/20:mdy.f=MouseDeltaY()/20:mdz.f=MouseWheel()*5
  If rmb
    vm.f=Sqr(Pow(vx.f,2)+Pow(vy.f,2)+Pow(vz.f,2))
    EntityFixedYawAxis(1,1,vx/vm,vy/vm,vz/vm)
    Yaw(EntityID(1),Degree(mdx),#PB_World|#PB_Relative)
  Else
    RotateEntity(0,mdy,-mdx,mdz,#PB_Relative)
    vx=EntityDirectionX(0)
    vy=EntityDirectionY(0)
    vz=EntityDirectionZ(0)
    Text3DCaption(0,StrF(w,2)+","+StrF(vx,2)+","+StrF(vy,2)+","+StrF(vz,2))
  EndIf
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
http://www.zeitgeistmovie.com

while (world==business) world+=mafia;
Post Reply