Page 1 of 1

dissapointed... [Solved]

Posted: Tue Oct 31, 2006 3:11 am
by GBeebe
ok, So i got this whole 3d engine thing figured out... or so i thought. I can make levels and all that jazz (using code, not a .bsp or whatever). But now, what I'm finding is that some entities that are in the background show through entities that are infront of it. I know that this happens with billboards, but I'm using created entities.

Help, anyone?

Posted: Tue Oct 31, 2006 12:21 pm
by Trond
Can you give an example in code?

here's the deal...

Posted: Wed Nov 01, 2006 12:23 am
by GBeebe
This seems to only happen with materials that have:
MaterialBlendingMode (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)
But i need this to display transparancies in PNG files.

[edit]
And I have 2 computers, and this happens on both...
Also, 1 machine can't load JPG files with LoadTexture.

Re: here's the deal...

Posted: Wed Nov 01, 2006 1:04 am
by PB
Again: we need to see some code that demonstrates the problem. No code = no help.

Posted: Wed Nov 01, 2006 1:52 am
by dracflamloc
Code does help, but sometimes its not practical, and sometimes people might know of the problem from experience without seeing code. I wouldn't bite peoples heads off.

k

Posted: Wed Nov 01, 2006 2:58 am
by GBeebe
Declare.l CreateShape(x.l, y.l, Shape.l, Texture.l)

#Rad = #PI / 180

Global MapWidth.l
Global Inside.f
Global ASteps.f


MapWidth.l = 100
Inside.f = (32 * MapWidth.l) / (2 * #PI)
ASteps.f = 360 / (32 * MapWidth.l)

Structure s_Vertex
;vertice
px.f
py.f
pz.f
;Normal
nx.f
ny.f
nz.f
;UV
u.f
v.f

EndStructure

Global Dim Vertices.s_Vertex(7)

Structure s_Face
face.w[3]
EndStructure

Dim Triangles.s_Face(4)

Procedure CalcNormals(P1, P2, P3, Negative.b)

If Negative
Vertices(P1)\nx = ((Vertices(P3)\py - Vertices(P2)\py) * (Vertices(P2)\pz - Vertices(P1)\pz)) - ((Vertices(P3)\pz - Vertices(P2)\pz) * (Vertices(P2)\py - Vertices(P1)\py))
Vertices(P1)\ny = ((Vertices(P3)\pz - Vertices(P2)\pz) * (Vertices(P2)\px - Vertices(P1)\px)) - ((Vertices(P3)\px - Vertices(P2)\px) * (Vertices(P2)\pz - Vertices(P1)\pz))
Vertices(P1)\nz = ((Vertices(P3)\px - Vertices(P2)\px) * (Vertices(P2)\py - Vertices(P1)\py)) - ((Vertices(P3)\py - Vertices(P2)\py) * (Vertices(P2)\px - Vertices(P1)\px))
Else
Vertices(P1)\nx = ((Vertices(P1)\py - Vertices(P2)\py) * (Vertices(P2)\pz - Vertices(P3)\pz)) - ((Vertices(P1)\pz - Vertices(P2)\pz) * (Vertices(P2)\py - Vertices(P3)\py))
Vertices(P1)\ny = ((Vertices(P1)\pz - Vertices(P2)\pz) * (Vertices(P2)\px - Vertices(P3)\px)) - ((Vertices(P1)\px - Vertices(P2)\px) * (Vertices(P2)\pz - Vertices(P3)\pz))
Vertices(P1)\nz = ((Vertices(P1)\px - Vertices(P2)\px) * (Vertices(P2)\py - Vertices(P3)\py)) - ((Vertices(P1)\py - Vertices(P2)\py) * (Vertices(P2)\px - Vertices(P3)\px))
EndIf


Length.f = Sqr( Vertices(P1)\px * Vertices(P1)\px + Vertices(P1)\ny * Vertices(P1)\ny + Vertices(P1)\nz * Vertices(P1)\nz)
If Length = 0 : Length = 1 : EndIf

; Vertices(P1)\nx / Length
; Vertices(P1)\ny / Length
; Vertices(P1)\nz / Length

Vertices(P2)\nx = Vertices(P1)\nx : Vertices(P3)\nx = Vertices(P1)\nx
Vertices(P2)\ny = Vertices(P1)\ny : Vertices(P3)\ny = Vertices(P1)\ny
Vertices(P2)\nz = Vertices(P1)\nz : Vertices(P3)\nz = Vertices(P1)\nz





EndProcedure

Procedure CalcNormals2(*P1.s_Vertex, *P2.s_Vertex, *P3.s_Vertex, Negative.b)

If Negative
*P1\nx = ((*P3\py - *P2\py) * (*P2\pz - *P1\pz)) - ((*P3\pz - *P2\pz) * (*P2\py - *P1\py))
*P1\ny = ((*P3\pz - *P2\pz) * (*P2\px - *P1\px)) - ((*P3\px - *P2\px) * (*P2\pz - *P1\pz))
*P1\nz = ((*P3\px - *P2\px) * (*P2\py - *P1\py)) - ((*P3\py - *P2\py) * (*P2\px - *P1\px))
Else
*P1\nx = ((*P1\py - *P2\py) * (*P2\pz - *P3\pz)) - ((*P1\pz - *P2\pz) * (*P2\py - *P3\py))
*P1\ny = ((*P1\pz - *P2\pz) * (*P2\px - *P3\px)) - ((*P1\px - *P2\px) * (*P2\pz - *P3\pz))
*P1\nz = ((*P1\px - *P2\px) * (*P2\py - *P3\py)) - ((*P1\py - *P2\py) * (*P2\px - *P3\px))
EndIf


Length.f = Sqr( *P1\px * *P1\px + *P1\ny * *P1\ny + *P1\nz * *P1\nz)
If Length = 0 : Length = 1 : EndIf

; Vertices(P1)\nx / Length
; Vertices(P1)\ny / Length
; Vertices(P1)\nz / Length

*P2\nx = *P1\nx : *P3\nx = *P1\nx
*P2\ny = *P1\ny : *P3\ny = *P1\ny
*P2\nz = *P1\nz : *P3\nz = *P1\nz





EndProcedure


InitEngine3D()
InitSprite()
InitSprite3D()
InitKeyboard()
InitMouse()

ScreenW = 640 ;800
ScreenH = 480;600
BitDepth = 16 ;This should be changed in settings
ProgramName.s = "tD Racers"
SpriteMode = 0 ; #PB_Sprite_Memory ;This should be changed in settings

;Allows us to use PNG files!
;UsePNGImageDecoder()

OpenScreen(ScreenW, ScreenH, BitDepth, ProgramName.s)




;Add3DArchive("Data\", #PB_3DArchive_FileSystem)
Add3DArchive("Data3\", #PB_3DArchive_FileSystem)

Tid = LoadTexture(#PB_Any, "ship.png")
Mid = CreateMaterial(#PB_Any, TextureID(Tid))
MaterialBlendingMode (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)
;MaterialAmbientColor(Mid, RGB(0, 0, 0))
MaterialFilteringMode(Mid, #PB_Material_None)
;MaterialSpecularColor(Mid, RGB(128, 128, 128))
;MaterialAmbientColor(Mid, RGB(128,128,128))
;DisableMaterialLighting(Mid, 1)
MaterialShadingMode(Mid, #PB_Material_Phong)





Ret_Mesh = CreateMesh(#PB_Any, 6)




Vertices(0)\px = 0 -32
Vertices(0)\py = 0 -32
Vertices(0)\pz = 100
Vertices(0)\u = 0.5
Vertices(0)\v = 0.125

Vertices(1)\px = 48 -32
Vertices(1)\py = 0 -32
Vertices(1)\pz = 100
Vertices(1)\u = 0.5 ;1
Vertices(1)\v = 0.5

Vertices(2)\px = 48 -32
Vertices(2)\py = 64 -32
Vertices(2)\pz = 100
Vertices(2)\u = 0; 1
Vertices(2)\v = 0.5

Vertices(3)\px = 0 -32
Vertices(3)\py = 64 -32
Vertices(3)\pz = 100
Vertices(3)\u = 0
Vertices(3)\v = 0.125

CalcNormals(3, 0, 1, 0)
CalcNormals(1, 2, 3, 0)

Triangles(0)\face[0] = 3
Triangles(0)\face[1] = 0
Triangles(0)\face[2] = 1

Triangles(1)\face[0] = 1
Triangles(1)\face[1] = 2
Triangles(1)\face[2] = 3



Vertices(4)\px = 48 -32
Vertices(4)\py = 0 -32
Vertices(4)\pz = 100
Vertices(4)\u = 0.5
Vertices(4)\v = 0.5

Vertices(5)\px = 64 -32
Vertices(5)\py = 0 -32
Vertices(5)\pz = 76
Vertices(5)\u = 0.5
Vertices(5)\v = 0.796875

Vertices(6)\px = 64 -32
Vertices(6)\py = 64 -32
Vertices(6)\pz = 76
Vertices(6)\u = 0
Vertices(6)\v = 0.796875

Vertices(7)\px = 48 -32
Vertices(7)\py = 64 -32
Vertices(7)\pz = 100
Vertices(7)\u = 0
Vertices(7)\v = 0.5

CalcNormals2(@Vertices(7), @Vertices(4), @Vertices(5), 0)
CalcNormals2(@Vertices(5), @Vertices(6), @Vertices(7), 0)


Triangles(2)\face[0] = 7
Triangles(2)\face[1] = 4
Triangles(2)\face[2] = 5

Triangles(3)\face[0] = 5
Triangles(3)\face[1] = 6
Triangles(3)\face[2] = 7

SetMeshData(Ret_Mesh, #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate | #PB_Mesh_Normal, Vertices(), 8)
SetMeshData(Ret_Mesh, #PB_Mesh_Face, Triangles(), 4)



Ret_Ent = CreateEntity(#PB_Any, MeshID(Ret_Mesh), MaterialID(Mid))

EntityRenderMode(Ret_Ent, #PB_Entity_CastShadow)
;EntityPhysicBody(Ret_Ent, #PB_Entity_BoxBody)
;SetEntityMass(Ret_Ent, 1)
;SetEntityFriction(Ret_Ent, 20)


For a = 0 To 100 Step 2
For b = -5 To 5 Step 2
CreateShape(a, b, 1, MaterialID(Mid))
Next
Next

;Add a caméra, indispensable if something is to be seen
#Camera = 0
CreateCamera(#Camera, 0, 0, 100, 100) ; Créate caméra
CameraBackColor(#Camera, RGB(0,0,0)) ; Back color is blue
CameraLocate(#Camera,0,0,500) ; Position the caméra

WorldShadows(#PB_Shadow_Additive)
CreateLight(1, RGB(255,255,255), 0, 0, 200)
;OpenLibrary(54,"Engine3D.dll")
; CallCFunction(54,"LightAttenuation",0,1)
AmbientColor(RGB(155, 155, 155))
;CameraRenderMode(#Camera, #PB_Camera_Wireframe)

;make fog
;Fog(RGB(127, 127, 127), 0.1, 450, 500)
Repeat

ClearScreen(0)

;{ Input
If ExamineKeyboard()
If KeyboardReleased(#PB_Key_1)
Ent_Rot + 90
EndIf

If KeyboardPushed(#PB_Key_Left)
KeyX = -1
ElseIf KeyboardPushed(#PB_Key_Right)
KeyX = 1
Else
KeyX = 0
EndIf

If KeyboardPushed(#PB_Key_Up)
KeyZ = 1
ElseIf KeyboardPushed(#PB_Key_Down)
KeyZ = -1
Else
KeyZ = 0
EndIf

If KeyboardPushed(#PB_Key_Home)
KeyY = 1
ElseIf KeyboardPushed(#PB_Key_End)
KeyY = -1
Else
KeyY = 0
EndIf

If KeyboardPushed(#PB_Key_PageUp)
RollZ = 3
Else
If KeyboardPushed(#PB_Key_PageDown)
RollZ = -3
Else
;RollZ = 0
EndIf
EndIf

If KeyboardPushed(#PB_Key_Z)
EnableWorldPhysics(1)
;WorldGravity(9.8)
EntityPhysicBody(Ret_Ent, #PB_Entity_BoxBody)
SetEntityMass(Ret_Ent, 1)
SetEntityFriction(Ret_Ent, 20)
EndIf

If KeyboardPushed(#PB_Key_Add)
Frame.f+0.005
EndIf
EndIf

If ExamineMouse()
MouseX = -MouseDeltaX()/2
MouseY = -MouseDeltaY()/2
EndIf
;}

;RotateCamera(#Camera, MouseX, MouseY, RollZ*2)
MoveCamera (#Camera, KeyX*2, KeyZ*2, KeyY*2)
;RotateCamera(#Camera, 0, 0, EntityAngleX(Ret_Ent))
;RotateEntity(Ret_Ent, 5, 0, 10.5)
; CameraLookAt(#Camera, EntityX(ret_ent), EntityY(ret_ent), EntityZ(ret_ent)) ; Point/orient the caméra towards the entity
; CameraLookAt(#Camera, 0, 0, 0) ; Point/orient the caméra towards the entity



RotateCamera(#Camera, MouseX, MouseY, RollZ*2)

;RotateEntity(ret_ent, 0, 0, Ent_Rot)
LightLocate(1, CameraX(#Camera), CameraY(#Camera), CameraZ(#Camera))


RenderWorld() ; Display the 3D world


FlipBuffers()
;Delay(10)

OnErrorResume()
Until KeyboardPushed(#PB_Key_Escape)
;Debug ret_ent
End


Procedure.l CreateShape(x.l, y.l, Shape.l, Texture.l)

;s_Vertex px py px
; ShipNfo\Gx = 0 + (Cos((ShipNfo\GAngle) * #Rad) * (MaxSpeed-1))
; ShipNfo\Gy = 0 + (Sin((ShipNfo\GAngle) * #Rad) * (MaxSpeed-1))


If Shape.l = 1
Dim Vert.s_Vertex(24)
Dim Tris.s_Face(2)


Vert(0)\px = (Cos( (ASteps * (x.l * 32)) * #Rad) * Inside)
Vert(0)\pz = (Sin( (Asteps * (x.l * 32)) * #Rad) * Inside)
Vert(0)\py = y.l * 32
Vert(0)\u = 0
Vert(0)\v = 0


Vert(1)\px = (Cos( (ASteps * ((x.l * 32) + 32)) * #Rad) * Inside)
Vert(1)\pz = (Sin( (ASteps * ((x.l * 32) + 32)) * #Rad) * Inside)
Vert(1)\py = y.l * 32
Vert(1)\u = 1 ;0.5
Vert(1)\v = 0

Vert(2)\px = (Cos( (ASteps * ((x.l * 32) + 32)) * #Rad) * (Inside + 32))
Vert(2)\pz = (Sin( (ASteps * ((x.l * 32) + 32)) * #Rad) * (Inside + 32))
Vert(2)\py = y.l * 32
Vert(2)\u = 1 ;0.5
Vert(2)\v = 1 ;0.5

Vert(3)\px = (Cos( (ASteps * (x.l * 32)) * #Rad) * (Inside + 32))
Vert(3)\pz = (Sin( (Asteps * (x.l * 32)) * #Rad) * (Inside + 32))
Vert(3)\py = y.l * 32
Vert(3)\u = 0
Vert(3)\v = 1 ;0.5


CalcNormals2(@Vert(3), @Vert(0), @Vert(1), 0)
CalcNormals2(@Vert(1), @Vert(2), @Vert(3), 0)

Tris(0)\face[0] = 3
Tris(0)\face[1] = 0
Tris(0)\face[2] = 1

Tris(1)\face[0] = 1
Tris(1)\face[1] = 2
Tris(1)\face[2] = 3

; Vert(4)\px =




R_Mesh = CreateMesh(#PB_Any, 6)

SetMeshData(R_Mesh, #PB_Mesh_Vertex | #PB_Mesh_UVCoordinate | #PB_Mesh_Normal, Vert(), 4)
SetMeshData(R_Mesh, #PB_Mesh_Face, Tris(), 2)



R_Ent = CreateEntity(#PB_Any, MeshID(R_Mesh), Texture.l)

EntityRenderMode(R_Ent, #PB_Entity_CastShadow)

;ProcedureReturn R_Ent

EndIf




EndProcedure

Posted: Wed Nov 01, 2006 3:00 am
by PB
> I wouldn't bite peoples heads off

LOL, if you think that's me biting someone's head off, then you need to search
for some of my previous posts. :twisted:

Anyway, he was asked by Trond to post some code, and he responded with
nothing that really helps. So it happens on 2 computers -- so what? How is
that meant to help us? He didn't even mention which OS they are running.
We need to see where his code is at to determine the best way to help. As
it stands, it's like him going to the doctor and saying he feels sick, both at
home and at work. How is the doctor supposed to help?

Edit: Good to see some code has been posted now.

Doctor...

Posted: Wed Nov 01, 2006 3:13 am
by GBeebe
Well by saying that the problem occurs when I have this line of code:

MaterialBlendingMode (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)

And it goes away when i don't have that line of code, above, is like telling the doctor that i only feel sick when i eat at Chi-Chi's.

Saying that it happens on 2 comps tells me that it's not just a fluke with one video card. I'm using Windows XP on both... Didn't know that Linux supported engine3d.

ship.png
Image

Re: Doctor...

Posted: Wed Nov 01, 2006 7:10 am
by PB
> Well by saying that the problem occurs when I have this line of code:
> MaterialBlendingMode (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)
> And it goes away when i don't have that line of code, above, is like telling
> the doctor that i only feel sick when i eat at Chi-Chi's

But that doesn't help at all, because we don't know how you've used it,
in what context, and so on. All we asked was for some code to show the
problem, not speculative code. Good to see you finally delivered. :)

> I'm using Windows XP on both... Didn't know that Linux supported engine3d

OS can be Win 95, 98, ME, 2K or XP -- not just Windows vs Linux. Because
now we can check if the problem exists on 9x based Windows, or NT-based,
or both. Many bugs in the past have been caused by such differences, so we
need to rule out all possibilities.

Re: here's the deal...

Posted: Wed Nov 01, 2006 8:45 am
by Comtois
GBeebe wrote:This seems to only happen with materials that have:
MaterialBlendingMode (Mid, #PB_Material_AlphaBlend | #PB_Material_Add)
But i need this to display transparancies in PNG files.

[edit]
And I have 2 computers, and this happens on both...
Also, 1 machine can't load JPG files with LoadTexture.
May be you can try ?

Code: Select all

MaterialBlendingMode (Mid, #PB_Material_AlphaBlend)
And replace

Code: Select all

R_Mesh = CreateMesh(#PB_Any, 6)
By

Code: Select all

R_Mesh = CreateMesh(#PB_Any, 1000)
Replace 1000 by the size of your mesh.

Posted: Wed Nov 01, 2006 10:53 am
by Trond
#PB_Material_Add
Now what do you think this means?

Do you think that when the texture is rendered it will replace the colour behind it?

Do you think that when the texture is rendered it will subtract its colour from the colour behind it?

Or maybe, do you think that when the texture is rendered it will add its colour to the colour behind it? :wink:

??

Posted: Thu Nov 02, 2006 2:56 am
by GBeebe
I tried it with and without #PB_Material_Add and it doesn't change anything.
I tried it with #PB_Material_Add only and all entities with that Material are semi-transparrent.

@Comtois
The size of my meshes are 4 and 8 vertices. I can change this number to anything, including zero, and nothing changes.

Has anyone tried my code?

I guess to rephrase my origional question:

How do I show Alpha Transparrancy levels set in PNG files without getting other entites to overlap them when they shouldn't be overlapping?

Figured it out.

Posted: Fri Nov 03, 2006 6:39 am
by GBeebe
I was just building the entities where they belong... I found that if I built the entities on the (0, 0, 0) point and then moving them to the place where they belonged, the problem stopped.

Thanks anyways.