Author Topic: Faces  (Read 7305 times)

0 Members and 1 Guest are viewing this topic.

dragoonreas

  • Seedling
  • **
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 35
  • Eufloria: Yes
Re: Faces
« Reply #75 on: June 21, 2011, 01:19:10 PM »
Code: [Select]
t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))

Perhaps this?
Where did tx, ty and tz go? ???

Code: [Select]
t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * tx) + (j * ty) + (k * tz))That's the answer I got using this site.

(click to show/hide)
« Last Edit: June 21, 2011, 01:33:22 PM by dragoonreas »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #76 on: June 21, 2011, 01:47:45 PM »
tx = Lx2 - Lx1

So our answers are actually the same.

It seems like we are dividing one dot product by another.  That's how a lot of people seem to be doing it..

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #77 on: June 21, 2011, 01:51:42 PM »
Lets have a look at ALL the code that governs this:


Code: [Select]
-- get plane coordinates
Px1 = vertex3dXtransformed[firstvertex]
Py1 = vertex3dYtransformed[firstvertex]
Pz1 = vertex3dZtransformed[firstvertex]

Px2 = vertex3dXtransformed[secondvertex]
Py2 = vertex3dYtransformed[secondvertex]
Pz2 = vertex3dZtransformed[secondvertex]

Px3 = vertex3dXtransformed[thirdvertex]
Py3 = vertex3dYtransformed[thirdvertex]
Pz3 = vertex3dZtransformed[thirdvertex]


-- get line coordinates
Lx1 = GetCameraX()
Ly1 = GetCameraY()
Lz1 = CameraZ

Lx2 = vertex3dXtransformed[vertexID]
Ly2 = vertex3dYtransformed[vertexID]
Lz2 = vertex3dZtransformed[vertexID]


-- get 2 vectors along the plane
-- PV1x stands for Plane Vector #1, X-coordinate

PV1x = Px2 - Px1
PV1y = Py2 - Py1
PV1z = Pz2 - Pz1

PV2x = Px3 - Px1
PV2y = Py3 - Py1
PV2z = Pz3 - Pz1

-- now find the cross product, which is a line perpendicular to the plane
-- PV1 X PV2 = normal vector!
i = (PV1y * PV2z) - (PV1z * PV2y)
j = (PV1z * PV2x) - (PV1x * PV2z)
k = (PV1x * PV2y) - (PV1y * PV2x)

-- for the line, calculate tx, ty, tz
tx = Lx2 - Lx1
ty = Ly2 - Ly1
tz = Lz2 - Lz1

t = ((i * (Lx1 - Px1)) + (j * (Ly1 - Py1)) + (k * (Lz1 - Pz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))

intersectX = (t * tx) + Lx1
intersectY = (t * ty) + Ly1
intersectZ = (t * tz) + Lz1


-- calculate distance from intersection
intersectdistance2d = (GetCameraX() - intersectX)^2 + (GetCameraY() - intersectY)^2
intersectdistance3d = math.sqrt((CameraZ - intersectZ)^2 + (intersectdistance2d))


if intersectdistance3d > distance3d then
-- return false if the vertex is in front of the face
return false
else
-- return true if the plane is closer than the vertex
return true
end
« Last Edit: June 21, 2011, 01:55:49 PM by annikk.exe »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #78 on: June 21, 2011, 02:10:49 PM »
I've tried 2 different versions of t.
One like this:

Code: [Select]
t = ((i * (Lx1 - Px1)) + (j * (Ly1 - Py1)) + (k * (Lz1 - Pz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))

And one like this:

Code: [Select]
t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))
Neither is working :<  But we're getting close now, I think...

Bonobo

  • Achiever
  • Old Oak
  • ****
  • Thank You
  • -Given: 79
  • -Receive: 8
  • Posts: 630
  • Was born, still alive.
    • German Mac Mailing Lists
  • Eufloria: Yes
Re: Faces
« Reply #79 on: June 21, 2011, 06:13:22 PM »
Ouf … http://www.myalgebra.com/algebra_solver.aspx shows two different solutions w/ mighty big square roots




<edit>

Dang. I missed a whole page of posts …

</edit>
Google+
Do you play Go? (aka iGo aka Baduk aka Weiqi)

Pilchard123

  • Tester
  • Old Oak
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 17
  • Posts: 904
  • Eufloria: Yes
Re: Faces
« Reply #80 on: June 21, 2011, 07:28:47 PM »
Are tx, ty and tz their own thing, or t*x, t*y, t*z? It has a _*massive*_ effect on the outcome.

To me, the t*tx is the same as (t^2)x, and that is what most other people would say as well.

What are you even trying to do?
« Last Edit: June 21, 2011, 07:35:05 PM by Pilchard123 »

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #81 on: June 21, 2011, 07:43:45 PM »
"tx" is NOT "t * x".
"tx" is a unique variable.  It represents the x-component of the vector of the line from L1 to L2.  I gave it a short name instead of something more descriptive to keep the calculations reasonably short.


I've had a breakthrough, though not where I was expecting.
I found a problem with my plane-overlapping-in-2D code.  It doesn't work well with horizontal or vertical edges.  Testing and writing code to trap for it now...  Seems like the only reason I thought it was working correctly before is because I had my test cube rotating constantly.

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #82 on: June 21, 2011, 08:56:21 PM »
I've almost cracked it.  Trapping for horizontal and vertical seems to work fine, and the vertices of static objects behave correctly now.

There's still a really bizarre problem, though.  The vertices on the right hand side of each static cube flicker.  I have no idea why.  Moving or zooming the camera seems to "excite" them to flicker more.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: Faces
« Reply #83 on: June 21, 2011, 09:04:22 PM »
Good to hear :)

I hope to make some mor emodels, it's very fun, maybe I'll even make an editor for it when you're done, who knows...

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #84 on: June 22, 2011, 09:35:52 AM »
A girl from another forum I post on has taken a look at the maths for the line-through-plane check and confirmed this is what the calculation for t should be:

Code: [Select]
t = ((i * (Px1 - Lx1)) + (j * (Py1 - Ly1)) + (k * (Pz1 - Lz1))) / ((i * (Lx2 - Lx1)) + (j * (Ly2 - Ly1)) + (k * (Lz2 - Lz1)))
She studies physics and this stuff is apparently quite simple for her so hopefully it's gonna work this time.  :>

So once I get this flickering issue sorted out, I'll have another crack at that and see if I can get it to work with expected behaviour.  :>

Now, what is up with this flickering, hmm?  It's bizarro.

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: Faces
« Reply #85 on: June 22, 2011, 11:32:49 AM »
Ohh, wow :o

How many more cracks are there?

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #86 on: June 22, 2011, 11:37:45 AM »
If by cracks you mean attempts, that number is undefined.. :p

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: Faces
« Reply #87 on: June 22, 2011, 12:00:15 PM »
Sounds scary...

Gonna do a little more relaxing things for now: creating a risk map, a proper risk, not the eufloria map I released :P

annikk.exe

  • Achiever
  • Ent
  • ****
  • Thank You
  • -Given: 0
  • -Receive: 0
  • Posts: 1,794
Re: Faces
« Reply #88 on: June 22, 2011, 12:49:41 PM »
This bug is really annoying.  I can't figure out why it produces this behaviour.  Very strange....

Aino

  • Ent
  • ******
  • Thank You
  • -Given: 1
  • -Receive: 21
  • Posts: 1,492
  • They'll eat you next!
  • Eufloria: Yes
Re: Faces
« Reply #89 on: June 22, 2011, 02:12:57 PM »
I know that feeling :/

Adventure Map is so annoying with that one bug... If I kept the Maps internaly in the file, it would get alot simplier, but harder to create maps...