Search Home Members Contacts
About Us
Products
Downloads
Community
Support
Pages: [1]
  Print  
Author Topic: 3d line  (Read 738 times)
Canning
Community Member
*
Posts: 592


« on: November 10, 2011, 10:02:18 PM »

I am wanting to draw a 3dline from my space ship in its current facing direction for a certain length.

I have to source vector, but how do I calculate the end vector?

thanks

Canning
Logged

I am using 2010 VB.NET and TV 6.5 with Windows 7
beyonder
Moderator
Community Member
*****
Posts: 463


« Reply #1 on: November 10, 2011, 10:35:48 PM »

I'm sure there are a few ways.

One that comes to mind is to create a Node and parent it to the ship. Then move the node in the Z a few meters away (or as far as you want). The Node will always be in front of the ship. So just draw a line then from the ship to the Node.

Do you know how to parent things?

Laters.  Smiley
Logged

"And what I saw scared me to the depths of my miserable soul. It was true, it was all a sham, it ain't real." - The Thirteenth Floor
willyg
Community Member
*
Posts: 31


« Reply #2 on: November 10, 2011, 11:11:17 PM »

Here is another way or approach...

I usually just place the following somewhere within my Do Loop after I render a ship.

ShipFOV1 = Ship.GetWorldPosition(Vector3(0, 0, 5))
ShipFOV2 = Ship.GetWorldPosition(Vector3(0, 0, 150))
Screen.DRAW_Line3D ShipFOV1.x, ShipFOV1.y, ShipFOV1.z, ShipFOV2.x, ShipFOV2.y, ShipFOV2.z, Globals.RGBA(0, 1, 0, 0.5)

Where ShipFOV1 & ShipFOV2 are declared as vectors.

This short green 3d line segment will move and turn with your ship.

---Hope this helps
Logged
Canning
Community Member
*
Posts: 592


« Reply #3 on: November 10, 2011, 11:26:17 PM »

Quote
Do you know how to parent things?
Sorry, no I do not. Where can I read up on this feature? Or can you give me a quick explanation? Smiley

I have this formula, that I would prefferably use:
Quote
dest_point(x,y,z) = source_point(x,y,z) + direction(x,y,z) * line_length
However, I am not sure how to convert my facing angle into a direction vector... is it a simple formula?

I have found this on the net for a 2d rotation:
Quote
X = (float)Math.Cos(angle);
Y = (float)Math.Sin(angle);
Can it be modified for a 3d vector?

Canning
« Last Edit: November 10, 2011, 11:41:42 PM by Canning » Logged

I am using 2010 VB.NET and TV 6.5 with Windows 7
beyonder
Moderator
Community Member
*****
Posts: 463


« Reply #4 on: November 11, 2011, 02:32:25 AM »

This is for VB6 for example.

Set Node1 = TVScene.CreateNode("Node1")
Node1.SetParent TV_NODETYPE_MESH, Spaceship.GetIndex, 0

'This will move the node 100 units in front of the ship.
Node1.SetPosition 0, 0, 100

Since it's parented it will move like the moon around the Earth. The node is a child of the ship. Now just draw a line between them.

That's my approach...


Logged

"And what I saw scared me to the depths of my miserable soul. It was true, it was all a sham, it ain't real." - The Thirteenth Floor
Canning
Community Member
*
Posts: 592


« Reply #5 on: November 11, 2011, 07:45:16 PM »

Here is my code:

Code:
        Dim Node1 As MTV3D65.TVNode

        Node1 = Scene.CreateNode("Node1")
        Node1.SetParent(MTV3D65.CONST_TV_NODETYPE.TV_NODETYPE_MESH, PlayerArray(currentIdentifier).mesh.GetIndex, 0)

        Node1.SetPosition(0, 0, 300)

However, when I draw the 3dline, the line draws itself to coordinate (0,0,300) rather than 300 units in front of my ship.

I see that the code you showed me is for vb6. Is there any difference in using it in VB2010 with TV6.5?

The y coordinate of the line is both the same for the source and destination coordinate. Because of this, am I correct in saying I can just calculate using 2d maths with trig?

I have tried this, yet it doesn't work:

    x = start_x + len * cos(angle);
    z = start_z + len * sin(angle);

thanks

Canning
« Last Edit: November 13, 2011, 07:14:08 PM by Canning » Logged

I am using 2010 VB.NET and TV 6.5 with Windows 7
Canning
Community Member
*
Posts: 592


« Reply #6 on: November 16, 2011, 07:07:24 PM »

Figured it out.

The problem is that at an angle of 0 radians draws the line straight to the right. I thought it should be straight up... I know now.

thanks guys

Canning
Logged

I am using 2010 VB.NET and TV 6.5 with Windows 7
Pages: [1]
  Print  
 
Jump to:  

Powered by SMF 1.1.3 | SMF © 2006-2007, Simple Machines LLC
Seo4Smf v0.2 © Webmaster's Talks