It is currently Sun Oct 25, 2020 2:45 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Issue with lines using 'opengl' lib
PostPosted: Wed Oct 07, 2020 7:17 pm 
Offline
Addict
Addict
User avatar

Joined: Wed Jun 11, 2003 9:33 pm
Posts: 4633
Location: Spa, relaxing and thinking, and learning...
I am trying perform a pseudo 2D lines manual dealing, and want to play with different widths of the lines.
But, at least here, the line has squared lapses, which might be due to VGA type, does someone know about this ?

The tip allows to manage each one of four points in a cubic Bezier scheme.
Please compile using 'opengl' subsystem library to see the failures.

Code:
InitEngine3D():InitSprite():InitKeyboard():InitMouse():InitSound()
OpenWindow(0,0,0,1280,720,"",#PB_Window_BorderLess|#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0),0,0,1280,720,1,0,0,#PB_Screen_WaitSynchronization)
Add3DArchive(#PB_Compiler_Home+"examples/3d/Data/Textures",#PB_3DArchive_FileSystem)
Enumeration Camaras
  #Camara
EndEnumeration
Enumeration Luces
  #Luz
EndEnumeration
Enumeration Texturas
  #LineaTextura
EndEnumeration
Enumeration Materiales
  #LineaMaterial
EndEnumeration
Enumeration Mallas
  #LineaMalla
  #CoordenadaBezier1Malla
  #CoordenadaBezier2Malla
EndEnumeration
Enumeration Entidades
  #CoordenadaBezier1
  #CoordenadaBezier2
EndEnumeration
Enumeration Nodos
  #Pivotcamara
EndEnumeration
Structure D3DXVECTOR3
  x.f
  y.f
  z.f
EndStructure
Macro OrbitarObjeto1SobreObjeto0(tecla=LeftControl,tipo1=Camera,objeto1=#Camara,tipo0=Node,objeto0=#Pivotcamara); <- el 'objeto1' orbita sobre el 'objeto0', y este debe ser nodo de 'objeto1'
  If KeyboardPushed(#PB_Key_#tecla#); <- mover el punto de vista
    ;para desplazar la camara hacia delante, atras, arriba, abajo, izq o der
    If mdx.f Or mdy.f Or mdz.f
      If mmb.b
        Move#tipo1#(objeto1#,mdx.f/200,-mdy.f/200,0,#PB_Local)
      Else
        Rotate#tipo0#(objeto0#,-mdy.f,-mdx.f,0,#PB_Relative)
        If mdz
          Move#tipo1#(objeto1#,0,0,-mdz.f,#PB_Local)
        EndIf
      EndIf
    EndIf
EndMacro
Macro crealineaBezier()
  CreateMaterial(#LineaMaterial,LoadTexture(#LineaTextura,"White.jpg")):DisableMaterialLighting(#LineaMaterial,#True)
  CreateMesh(#LineaMalla,#PB_Mesh_LineStrip,#PB_Mesh_Static)
  DataSection
    puntosBezier:
    Data.f -1,0,0.5,-0.333333,1,0.5,0.333333,-1,0.5,1,0,0.5
  EndDataSection
  Dim puntos.D3DXVECTOR3(3)
  Restore puntosBezier
  For i.a=0 To 3
    Read.f puntos(i.a)\x
    Read.f puntos(i.a)\y
    Read.f puntos(i.a)\z
    MeshVertex(puntos(i)\x,puntos(i)\y,puntos(i)\z,i/3,i/3,$33F422)
  Next
  FinishMesh(#False):SetMeshMaterial(#LineaMalla,MaterialID(#LineaMaterial))
  AttachNodeObject(#Pivotcamara,MeshID(#LineaMalla))
  glLineWidth_(15) ; para poner grosor a las lineas compilar con el subsystem 'opengl'
EndMacro
Procedure LineaBeziercubico(Array lp.D3DXVECTOR3(1),res.f=0.02)
  Protected t0.f=0.0,t1.f=1.0,b.D3DXVECTOR3,b0.D3DXVECTOR3=lp(3),pt03.f,pt13.f,pt102.f,pt012.f
  UpdateMesh(#LineaMalla,0)
  While t1.f>=-res
    pt03.f=Pow(t0.f,2):pt13.f=Pow(t1.f,2):pt102.f=t1.f*pt03.f:pt012.f=t0.f*pt13.f:pt03.f*t0.f:pt13.f*t1.f
    b\x=lp(0)\x*pt03.f+3*lp(1)\x*pt102.f+3*lp(2)\x*pt012.f+lp(3)\x*pt13.f
    b\y=lp(0)\y*pt03.f+3*lp(1)\y*pt102.f+3*lp(2)\y*pt012.f+lp(3)\y*pt13.f
    b\z=lp(0)\z*pt03.f+3*lp(1)\z*pt102.f+3*lp(2)\z*pt012.f+lp(3)\z*pt13.f
    MeshVertexPosition(b\x,b\y,b\z)
    b0=b
    t0.f+res.f:t1.f-res.f
  Wend
  FinishMesh(#False)
EndProcedure
CreateLight(#Luz,$EEEEEE,4,4,2,#PB_Light_Point)
SetLightColor(#Luz,#PB_Light_SpecularColor,$FFFFFF):AmbientColor($222222)
CreateCamera(#Camara,0,0,100,100):CreateNode(#Pivotcamara,0,0,0):AttachNodeObject(#Pivotcamara,CameraID(#Camara)):CameraRange(#Camara,0.1,10000):CameraBackColor(#Camara,$181911):MoveCamera(#Camara,0,0,8.33,#PB_Absolute)
Pitch(NodeID(#Pivotcamara),-90,#PB_World)
crealineaBezier()
  CreateSphere(#CoordenadaBezier1Malla,0.05)
  CreateEntity(#CoordenadaBezier1,MeshID(#CoordenadaBezier1Malla),#PB_Material_None)
  CreateEntity(#CoordenadaBezier2,MeshID(#CoordenadaBezier1Malla),#PB_Material_None)
  MoveEntity(#CoordenadaBezier1,puntos(1)\x,puntos(1)\y,puntos(1)\z,#PB_Absolute)
  MoveEntity(#CoordenadaBezier2,puntos(2)\x,puntos(2)\y,puntos(2)\z,#PB_Absolute)
  AttachNodeObject(#Pivotcamara,EntityID(#CoordenadaBezier1))
  AttachNodeObject(#Pivotcamara,EntityID(#CoordenadaBezier2))
Repeat
  ExamineMouse():ExamineKeyboard()
  lmb.b=MouseButton(#PB_MouseButton_Left):rmb.b=MouseButton(#PB_MouseButton_Right)
  mdx.f=MouseDeltaX()/10:mdy.f=MouseDeltaY()/10:mdz.f=MouseWheel()/3
  Eventodeventana.i=WindowEvent()
  LineaBeziercubico(puntos.D3DXVECTOR3(),0.05)
  OrbitarObjeto1SobreObjeto0()
  ElseIf lmb.b
    If KeyboardPushed(#PB_Key_LeftShift)
      puntos(0)\x+mdx/20:puntos(0)\y-mdy/20
      MoveEntity(#CoordenadaBezier1,puntos(1)\x,puntos(1)\y,puntos(1)\z,#PB_Absolute)
      MoveEntity(#CoordenadaBezier2,puntos(2)\x,puntos(2)\y,puntos(2)\z,#PB_Absolute)
    Else
      puntos(1)\x+mdx/20:puntos(1)\y-mdy/20
      MoveEntity(#CoordenadaBezier1,puntos(1)\x,puntos(1)\y,puntos(1)\z,#PB_Absolute)
      MoveEntity(#CoordenadaBezier2,puntos(2)\x,puntos(2)\y,puntos(2)\z,#PB_Absolute)
    EndIf
  ElseIf rmb.b
    If KeyboardPushed(#PB_Key_LeftShift)
      puntos(3)\x+mdx/20:puntos(3)\y-mdy/20
      MoveEntity(#CoordenadaBezier1,puntos(1)\x,puntos(1)\y,puntos(1)\z,#PB_Absolute)
      MoveEntity(#CoordenadaBezier2,puntos(2)\x,puntos(2)\y,puntos(2)\z,#PB_Absolute)
    Else
      puntos(2)\x+mdx/20:puntos(2)\y-mdy/20
      MoveEntity(#CoordenadaBezier1,puntos(1)\x,puntos(1)\y,puntos(1)\z,#PB_Absolute)
      MoveEntity(#CoordenadaBezier2,puntos(2)\x,puntos(2)\y,puntos(2)\z,#PB_Absolute)
    EndIf
  EndIf
  TimeSinceLastFrame.i=RenderWorld(50)
  FlipBuffers():Delay(9)
Until KeyboardPushed(#PB_Key_Escape)

_________________
http://www.zeitgeistmovie.com

While world=business:world+mafia:Wend


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye