GLBasic forum

Main forum => GLBasic - en => Topic started by: Hatonastick on 2008-Sep-04

Title: Couple of questions.
Post by: Hatonastick on 2008-Sep-04
Chances are they have already been answered somewhere in the forum, my search-fu is weak though.  Nothing that I could see as relevant.  Anyway, I have a couple of questions regarding objects created with X_OBJ for a project I'm about to start working on:

1) X_OBJ only creates solid shapes constructed from triangles, so how would I add X_LINE style lines to an object?  I'm trying to do a mixture of wireframe and solid graphics. ie. retro style 3D (preferably hardware accelerated though)

2) Can I alter the vertices of an X_OBJ created object on the fly? eg. I build a cube using X_OBJ, then want to turn it into an oblong shape.

There's a reason why I'm looking to do these on the fly and not in a 3D editor.

[Edited for clarity]
Title: Re: Couple of questions.
Post by: Moru on 2008-Sep-04
Yes, I would like to know this too. And the search-fu is not only weak with you, I get rubish results every time I try to search on something.
Title: Re: Couple of questions.
Post by: Hatonastick on 2008-Sep-04
Hmm actually I just remembered I had an old B3D snippet laying about somewhere that might take care of 1) if I convert it.  I think it creates extremely thin cylinders (my B3D is so rusty I'm having trouble understanding it off the top of my head - time to reinstall it :)).  Does OpenGL handle individual lines natively?  I think under DirectX the driver support for lines in 3D was pretty iffy and depended on the actual graphics card.  That's what I was told once by someone, so sorry if that's incorrect.  This new fangled 3D thing isn't really my area. ;)

Code (glbasic) Select
; #########################################################################
; #  3D Accelerated Line Library (c)2004 Tim Fisher                       #
; #  This code is public domain, do wih it what you like.   #
; #########################################################################

; Adjust line thickness here:
; d# = (Sqr( dx*dx + dz*dz ) * 8.0)
; The smaller the thicker. 8 is good For 1024x768

Global screenwidth#
Global screenheight#

Global LineSurf
Global LineTex
Global LineCam
Global LineMesh
Global Pivot0 = CreatePivot()
Global Pivot1 = CreatePivot()

Function InitLine3d()

LineTex = CreateTexture(16,16,2)

SetBuffer TextureBuffer(LineTex)
Line 7,0,7,15
Line 8,0,8,15
SetBuffer BackBuffer()

LineCam = CreateCamera()
PositionEntity LineCam,0,0,-40
CameraProjMode LineCam,2
CameraZoom LineCam,0.1

LineMesh = CreateMesh()
LineSurf = CreateSurface(LineMesh)
EntityBlend LineMesh,3
EntityTexture LineMesh,LineTex
EntityFX LineMesh,3

screenwidth = GraphicsWidth()
screenheight = GraphicsHeight()

End Function

Function ClsLines()

ClearSurface(LineSurf)

End Function


Function Line3d( Mesh,x0#,y0#,x1#,y1# , r=255, g=255, b=255, w# = .25 )

sx# = x0/screenwidth
x0# = (sx * 20.0) - 10
sy# = y0/screenheight
y0# = 7.5 - (sy * 15)
sx# = x1/screenwidth
x1# = (sx * 20.0) - 10
sy# = y1/screenheight
y1# = 7.5 - (sy * 15)

If Mesh = 0
Mesh = CreateMesh()
LineSurf = CreateSurface(Mesh)
Else
LineSurf = GetSurface(Mesh,1)
If CountVertices(LineSurf)>30000
LineSurf = CreateSurface(Mesh)
EndIf
End If

PositionEntity Pivot0, x0,0,y0
PositionEntity Pivot1,x1,0,y1
PointEntity Pivot0,Pivot1
TFormNormal 0,0,1,Pivot0,0
dx# = TFormedX()*w
dy# = TFormedZ()*w

v0 = AddVertex( LineSurf , x0 - dy , y0 + dx , 0 ,0,0 )
v1 = AddVertex( LineSurf , x1 - dy , y1 + dx , 0 ,0,1 )
v2 = AddVertex( LineSurf , x1 + dy , y1 - dx , 0 ,1,0 )
v3 = AddVertex( LineSurf , x0 + dy , y0 - dx , 0 ,1,1 )

For v = v0 To v3
VertexColor LineSurf, v, r,g, b
Next

AddTriangle LineSurf,v0,v1,v2
AddTriangle LineSurf,v2,v3,v0

Return Mesh

End Function


Title: Re: Couple of questions.
Post by: Kuron on 2008-Sep-04
I wish I could help, but this is way above my pay grade.
Title: Re: Couple of questions.
Post by: Kitty Hello on 2008-Sep-05
No, if you want wireframes, you can use X_GETFACE to receive the object's vertices and then X_LINE to draw it.
Have to multiply with current matrix then. Oh dear. That's bad.

You could do it with the OpenGL wrapper.

Code (glbasic) Select

glBegin(GL_LINES)
FOREACH line
glVertex3f(x,y,z);
...
NEXT
glEnd();
Title: Re: Couple of questions.
Post by: Hatonastick on 2008-Sep-05
I just had a look at what you are suggesting and I'm starting to think this might be a whole lot harder than I first thought, I may have to put this on hold until I can come up with another solution.

Thanks for your time guys.
Title: Re: Couple of questions.
Post by: Kitty Hello on 2008-Sep-05
model it and use transparend textures, so you have the "lines" on your texture.
Title: Re: Couple of questions.
Post by: Hatonastick on 2008-Sep-05
Thanks for the suggestions Gernot, unfortunately that wont work in this particular case.  It's flat-shaded polygons, and players will get up close and personal to the graphics - which of course is when textured lines start to look not so good.  Anyway don't worry about it mate.  I don't think I'm ready for this game just yet.  Going to do one of my other ideas first.  This one is simpler (and 2D which I'm more familiar with) and probably more achievable at my current skill level. :)