Documentation: TransFormMesh() not right?

Everything related to 3D programming
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Documentation: TransFormMesh() not right?

Post by IdeasVacuum »

Concerning the new x,y,z positions of the mesh:

Using 'x' as an example
In the parameters list, Doc says "New 'x' position of the mesh, relative to its node"

If the mesh is not a member of an Entity and the Entity is not attached to a node, it should say:
"New absolute (world) 'x' position of the mesh"

The conumdrum is - should a mesh be transformed once it is a member of an Entity, which in turn is a member of a Node?

If the Node is specifically for the one Entity, then the Node can be transformed, else the Entity can be transformed.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
applePi
Addict
Addict
Posts: 1404
Joined: Sun Jun 25, 2006 7:28 pm

Re: Documentation: TransFormMesh() not right?

Post by applePi »

IdeasVacuum , look the following example about TransFormMesh, which i have posted before. since there is no TransFormMesh keyword inside 3D examples.
when you press arrow keys you can detach a triangle and moving it away from the mesh. but i can't decide if the scalex,scaley,scalez and rotatex,rotatey,rotatez are working okay or not.
save the example to 3D folder:

Code: Select all

Declare CreateFigure_(FigNum, size)
#Win=8
#node=9
EnableExplicit
Define Mat2,rot,xx.f,yy.f,zz.f,yyy.l,ss.s,k.l,Event.l
InitEngine3D()
InitSprite()
InitKeyboard()
Add3DArchive("Data/Textures", #PB_3DArchive_FileSystem)
;oooooooooooooooooooooooooooooooooooooooooooooooooooooooo
OpenWindow(#Win,0,0,640,480,"Use arrow keys to detach a triangle",#PB_Window_SystemMenu | #PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(#Win),0,0,640,400,1,0,0)
CreateCamera(0, 0, 0, 100, 100)
MoveCamera(0,0,0,300)
CameraLookAt(0, 0,0, 0)
CameraBackColor(0,0)
CreateLight(1,RGB(255,255,255),0,0,0)
Mat2=CreateMaterial(0, LoadTexture(0, "ValetCoeur.jpg"))
MaterialCullingMode(0, 1)
CreateFigure_(1,150)
CreateEntity(1,MeshID(1),Mat2,400,-350,0) 
CreateNode(#node , 0, 0, 0)

AttachNodeObject(#node, EntityID(1))
;TransformMesh(#Mesh, x, y, z, ScaleX, ScaleY, ScaleZ, RotateX, RotateY, RotateZ [, SubMesh])

Repeat
  Event = WindowEvent()
  zz=0:xx=0
  ExamineKeyboard()
  yyy+1
  RotateNode(#node, 0, rot, 0 )
  rot+1  :  If rot>360 :rot= 1 :EndIf
  RenderWorld()
  FlipBuffers()

  If KeyboardPushed(#PB_Key_Up)
    zz=zz-2
    TransformMesh(1, xx, yy, zz, 1, 1, 1, 0, 0, 0 , 2)
       
  ElseIf KeyboardPushed(#PB_Key_Down)
    zz=zz+2
    TransformMesh(1, xx, yy, zz, 1, 1, 1, 0, 0, 0 , 2)
        
  
  ElseIf KeyboardPushed(#PB_Key_Right)
    xx+2
    TransformMesh(1, xx, yy, zz, 1, 1, 1, 0, 0, 0 , 2)
      
  ElseIf KeyboardPushed(#PB_Key_Left)
    xx-2
    TransformMesh(1, xx, yy, zz, 1, 1, 1, 0, 0, 0 , 2)
        
  EndIf
  
Until KeyboardPushed(#PB_Key_Escape) Or Event = #PB_Event_CloseWindow

Procedure CreateFigure_(FigNum, Size)
  Protected.l i,r
  Protected.f x, y, z,u, v
  Protected.w t1, t2, t3
  CreateMesh(FigNum,#PB_Mesh_TriangleList,#True)
  r=0
  AddSubMesh()
  For i=0 To 11
    ;note that backside vertices begins with v12
    r=r+1
    If r=4
      r=1
      AddSubMesh()
    EndIf  
    Read.f x : Read.f y : Read.f z
    Read.f u: Read.f v
    MeshVertexPosition(x * size, y * Size, z * Size)
    MeshVertexTextureCoordinate(u, v)
    ;;wwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwww
    
  Next i
  Restore Triangles
  For i=0 To 3
    Read.w t1 : Read.w t2 : Read.w t3
    MeshFace(t1, t2, t3)
  Next i
  FinishMesh(#True)
  
EndProcedure


DataSection
  
  Vertices:  
  Data.f -2.5, 2.5 ,0,    1,0.5
  Data.f -2.5, 3   ,0,    1,0 
  Data.f -3,   3   ,0,     0,0
  
  Data.f -3,   3   ,0,     0,0
  Data.f -3,   2.5 ,0,     0,0.5
  Data.f -2.5, 2.5 ,0,     1,0.5
  
  
  Data.f -2.5, 2   ,0,     1,1
  Data.f -2.5, 2.5 ,0,     1,0.5
  Data.f -3,   2.5 ,0,     0,0.5
  Data.f -3,   2.5 ,0,     0,0.5
  Data.f -3,   2   ,0,     0,1
  Data.f -2.5, 2   ,0,     1,1
  
    
  Triangles:
  Data.w 0,1,2
  Data.w 3,4,5
  Data.w 6,7,8
  Data.w 9,10,11
  
      
EndDataSection
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: Documentation: TransFormMesh() not right?

Post by IdeasVacuum »

Hi ApplePi

....you have gone off topic a bit there :mrgreen: This post is about the documentation. For the record, in addition to the existing Move, Scale and Rotate commands for Entities and Nodes, I think it would be good to have a transform command for each, yeilding more elegant code - but of course we can set that up as a procedure.

Currently, the Documentation assumes that the Mesh to be Transformed is a member of an Entity which is attached to a node. However a Transform can be performed on a Mesh whether or not it has a Parent and/or Grandparent :D and there are advantages in applying a Transform before it is logically linked, for example if it is to be instanced many times. You might use a transform to turn a Cube primative into a rectangular block (prism).
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
Post Reply