### Author Topic: Single Object3D (addTriangle) or Vectors of Object3D Primitives?  (Read 6509 times)

#### ToddMcF2002

• long
• Posts: 103
##### Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« on: April 05, 2007, 04:59:20 pm »
This is design question really - impacting code efficiency and its performance impact.

Currently I'm composing variable length/width lines out of Vectors of Object3D Primitive Plane.

I can't work with a model because of the variability ie. the rectangle resizes its length and rotation on the x/z plane based on the mouse coords.  Think Lightning Bolt for example.  It can be strait or have variable directional adjustments between SimpleVector source and target.

The question is this:

Its it "worth" investigating building a Rectangle primitive for performance?  Its really a question of whether there is an advantage to having a single Object3D I'll have to create and destroy or a vector of them (which is my current approach).  In the end, the total number of underlying Triangle faces is the same isnt it?

Is there any performance advantage or disadvantage?

This is an important issue for me since I'm using this approach to build other "pathing" objects as part of a larger Particle effect factory.

#### ToddMcF2002

• long
• Posts: 103
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #1 on: April 05, 2007, 07:20:12 pm »
Egon?  Anyone?  I'm planning on doing a good chunk of coding this weekend so any input would really help!

#### ToddMcF2002

• long
• Posts: 103
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #2 on: April 06, 2007, 12:08:05 am »
Ha ha ha ha!!!!

How could I be so stupid?  Oh well its not for the first time.  Creating rectangular plane is only 2 triangles.  Geesh!!!

I guess I need to start creating my own primitives for this kind of activity and lay off the stupid pills.

#### Hrolf

• int
• Posts: 84
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #3 on: April 06, 2007, 02:23:06 am »
I guess I need to start creating my own primitives for this kind of activity and lay off the stupid pills.
You need pills to be stupid? I can do it naturally!

Mind you, I have thought it would be nice to have a method like addQuad(x,y,z,x1,y1,z1,u,v,u1,v1) purely for convenience...

#### ToddMcF2002

• long
• Posts: 103
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #4 on: April 06, 2007, 06:34:27 am »
You need pills to be stupid? I can do it naturally!

Mind you, I have thought it would be nice to have a method like addQuad(x,y,z,x1,y1,z1,u,v,u1,v1) purely for convenience...

I just finished the lightning bolt implementation.

It is basically two rectangular planes casted from source to target, one vertical and one horizontal (a very long "plus").  I then apply a zig zag texture on both and set transparency.  At each paint I toggle a few textures back and forth and play with lighting.  I did this years ago in the Unreal 1 Editor and it looks pretty much the same (a good thing).

One thing though - I'm not quite happy with my math (or lack there of).  Its the stupid pills again.

Basically - it is easy to create the long ends of a rectangle for a source and a target (y is constant for me!).  The problem is the width on the x/z plane.  You need a perpendicular to the line between the points to create a width.

I just could not get my small mind around it.  Initially I was creating this new "Rectangle" primitive totally in place - ie. pre-rotated between the source and target.  To cheese on calculating the perpendicular on my rectangle (ie. the short end widths) I created the Rectangle on the y axis (like a blade on its edge).  I thought hey -  it will be easy to then simply rotate it by PI/2 to create the horizontal Rectangle.  Right?  Rigghhht???  Nope!  The problem is of course the RotationMatrix.  I just couldnt get a decent one on the Rectangle and I tried for hours.  Every rotation was really messed up and the stupid pills where in full effect.

Finally after pulling my hair out, I found another way.  Far easier.  I calculated the length of the line (that math I know!) and built it horizontally at the World origin this time.  That lets me skip the nasty perpendicular calculation since the rectangle is square to the world.  So I just add and subtract some X since there is no rotation.  Then I moved it to the center point between source and target and rotated it to match the source's yRotation.

I guess that's not too bad.  It looks really nice and now I can use this much lighter weight Rectangle concept elsewhere.

My next hurdle is to apply this same approach to creating a rectangle on the ground that follows the mouse while pivoting on a source at the other end.  If you have ever played Temple Of Elemental Evil you know what I mean.  Its a line indicating the path you are going to walk if you click.  I think I can do the same thing with one exception - I'll need 2 invisible dummy objects.  One will chase the mouse.  The other will track the object by rotating as it moves.  I need to maintain that Y axis rotation so my math works.

#### cyberkilla

• float
• Posts: 413
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #5 on: April 16, 2007, 09:52:14 pm »
Sounds interesting. I will probably need to look into this soon.
http://futurerp.net - Text Based MMORPG
http://beta.rpwar.com - 3D Isometric MMORPG

#### ToddMcF2002

• long
• Posts: 103
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #6 on: April 16, 2007, 10:31:43 pm »
I forgot to report back (in case anyone cares  ) that the Temple of Elemental Evil walking the user defined path nodes worked perfectly.  All that struggle with the lightning bolt math payed off.

Also I how have a "NWN" style camera that pans, zooms, and is height adjustable - meaning the angle to the x/z plane goes from near 0 (over the sholder) to 90 degrees (strait overhead).

Do all screenshots have to be linked or can you upload them here?  My fireball sort of stinks but the lightingbolt and the path nodes look pretty good.

#### EgonOlsen

• Posts: 12065
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #7 on: April 16, 2007, 10:36:01 pm »
Do all screenshots have to be linked or can you upload them here?  My fireball sort of stinks but the lightingbolt and the path nodes look pretty good.
You can send them to me, i'll gladly host them.

#### ToddMcF2002

• long
• Posts: 103
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #8 on: April 17, 2007, 04:27:28 am »
Thanks Egon...

I'll mail them now.  Just FYI folks - those are TEST models I downloaded from who knows where - placeholders.  Not trying to take credit for them....  Also that blit image in the corner is just another test.

Also for some reason my hardware rendered custom cursors don't show up.  Too bad - neat gauntlet and sword...

Here are the pics I'm sending:
- Lightning bolt
- Setting up the nodes
- Running the nodes

#### EgonOlsen

• Posts: 12065
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #9 on: April 17, 2007, 07:03:13 am »

#### ToddMcF2002

• long
• Posts: 103
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #10 on: April 17, 2007, 03:48:33 pm »
Just a note on what you are looking at:

The lightning bolt is using 2 Object3D's each with two triangles.  One is on the X/Z plane and the other is on the Y/Z plane (a long "plus").  Obviously they are rendering textures with transparency.  The textures are toggled with every paint cycle so it looks very dynamic.  I also allocate a number of Light objects along its length which gives it a strobe effect you can't see in the screenshot.

Because you can set the tiling properties for the texture placement you can easily add more "bolts".  Here there are only 2 - ie. no tiling and one on the vertical plane and one on the horizontal.  I tested 4 and 5 on each plane.

Anyway - it looks great animated and doesnt hit the framerate at all really.  The "node" system uses the same math for vector origin and target but only works on the X/Z plane.  Its surprisingly smooth when you draw the lines realtime - they "chase" the mouse very smoothly elongating and pivoting.

#### raft

• Posts: 1991
##### Re: Single Object3D (addTriangle) or Vectors of Object3D Primitives?
« Reply #11 on: April 17, 2007, 04:29:42 pm »
quite impressive