Linepick on the inside of a cylinder.

Blitz3D Forums/Blitz3D Programming/Linepick on the inside of a cylinder.

Zeotrope(Posted 2012) [#1]
 Graphics3D 1920,1080,32,0
SetBuffer BackBuffer()


trk=LoadMesh( "trk001.3ds" )
car=LoadMesh( "car.3ds" )

EntityPickMode car,2
EntityPickMode trk,2


camera=CreateCamera()
PositionEntity camera,00,10,-10

While Not KeyHit(1)

    PointEntity camera,car
	
	x# = EntityX(car) : z# = EntityZ(car) : y# = EntityY(car) 
	
	LinePick x#,y#,z#,0,-100,0
	
	AlignToVector car,PickedNX(),PickedNY(),PickedNZ(),2

	MoveEntity car,1,0,0

	
	UpdateWorld
	RenderWorld
	Flip
Wend
End



I am unsure why the above code wont work. But what I want is this: I have a huge open ring. I have a small space craft. I want the space craft to travel at speed around the inside of the ring. I was assuming that I would use the ALIGNTOVECTOR command. The only other time i've used this command was with the Blitz Terrain and therfore I used the TERRAINY() command.

As you can see, the space ship is called "CAR" and the ring is called "TRK"

Any code suggestions...as mine wont align to the vector.


jkrankie(Posted 2012) [#2]
you probably need to flip the cylinder before picking the inside of it as the normals will be facing the wrong way otherwise.

Cheers
Charlie


Zeotrope(Posted 2012) [#3]
ALready flipped it in Max. All normals are facing the inside.

Last edited 2012


Stevie G(Posted 2012) [#4]
Don't set a pickmode 2 on the car, you may be hitting it first!

Linepick from slightly above the car and then down, e.g.

LinePick x#,y#+10,z#,0,-110,0

Check that you are actually hitting something before aligning. There are a couple of options ..

(A) Linepick can return the entity which has been hit if used like so ...

Picked = LinePick( x#,y#+10,z#,0,-110,0 )
If Picked > 0
;do alignment
Endif

(B) PickedTime() returns the % (0.0 to 1.0) to let you know how far along the pick vector contact was made. If the result is 1.0, nothing is hit.

LinePick x#,y#+10,z#,0,-110,0
If PickedTime() < 1.0
;do alignment
Endif

Hope this helps.


Zeotrope(Posted 2012) [#5]
Thanks Stevie, will give it a whirl.

As for "hitting" ....The end goal I need to accomplish is this....(overview)

Racing game whete there are multiple vehicles (space craft) traveling in the same direction around the inside of a loop. Each full loop represenrs
a lap completed etc.

The ships themselves should hover a few meters from the surface of the track. So no contact is made at all.

The track itself was modelled in 3D Studio and is a simple ring consisting of 128 facets.

More advanced tracks will be designed later that contain twists (corkscrews) and turns. But prior to those designs, I need to test things
on a simple loop.

My only other previous experience with ALIGNTOVECTOR was with a Tank
rolling on a Blitz3D native terrain. This was easy as the commant TERRAINY
was used. Is there another command I can use that works the same?

Thanks for the ideas tho. Will see how I go. Also, if the above
description I just gave makes a difference to your suggestions above,
please let me know.

Cheers.

Last edited 2012


RemiD(Posted 2012) [#6]
Thermo>>Post a zip with your meshes and code so we can really see what is happening, and also we can check the normals.


Zeotrope(Posted 2012) [#7]
Ok....here is the link to my code. Any help would be much appreciated.

Click here!


Zeotrope(Posted 2012) [#8]
Also, can somebody answer this?

Can AlignToVector work upside down? Ie: Can it work on a stunt track where there is a loop?

Can I see a simple code example showing a box following the terrain. (Not a blitz terrain, but a custom mesh?)

All I want to do is have my ship follow the inside of a cylinder using the AlignToVector command. It needs to be the same distance from the surface of the cylinder at all times. Anyone?


RemiD(Posted 2012) [#9]
Here is an example on how to achieve this effect :

Graphics3D(800,600,32,2)
SetBuffer(BackBuffer())

Camera = CreateCamera()
CameraRange(Camera,0.1,1000)
PositionEntity(Camera,0,0,0)

Origine = CreateCube()
ScaleEntity(Origine,0.01/2,0.01/2,0.01/2)
PositionEntity(Origine,0,0,0)
EntityColor(Origine,255,000,000)

TrackMesh = LoadMesh("trk001.3ds")
PositionEntity(TrackMesh,0,0,0)
EntityPickMode(TrackMesh,2)

CarMesh = LoadMesh("car.3ds") 
RotateMesh(CarMesh,0,90,0) ;Rotates the mesh of the car so the local VZ corresponds to moving forward
PositionMesh(CarMesh,0.09,-0.265,0) ;The mesh of the car origine was not centered correctly on the X axis and Y axis of the World origine...
PositionEntity(CarMesh,0,0,0)
RotateEntity(CarMesh,0,-90,0) ;Rotates the CarMesh entity so that it is oriented how you want
MoveEntity(CarMesh,0,0.5,0) ;Moves the CarMesh entity above the track

PositionEntity(Camera,EntityX(CarMesh,True),EntityY(CarMesh,True),EntityZ(CarMesh,True))
;=====Remove this part for a side view=====
RotateEntity(Camera,EntityPitch(CarMesh,True),EntityYaw(CarMesh,True),EntityRoll(CarMesh,True))
MoveEntity(Camera,0,1,-3)
EntityParent(Camera,CarMesh,True)
;==========================================

Light=CreateLight(1) 

While Not KeyHit(1)

 Cls()

 MoveEntity(CarMesh,0,0,1) ; Moves the CarMesh entity forwards (on the local Z axis)
 ;This time the CarMesh entity origine is above the track so we can linepick from here.
 CarX# = EntityX(CarMesh,True)
 CarY# = EntityY(CarMesh,True) 
 CarZ# = EntityZ(CarMesh,True)
 TFormVector(0,-100,0,CarMesh,0) ;Creates a vector which starts from the CarMesh entity coordinates and who goes below the entity 
 LinePick(CarX#,Cary#,Carz#,TFormedX(),TFormedY(),TFormedZ())
 PositionEntity(CarMesh,PickedX(),PickedY(),PickedZ()) ;Positions the CarMesh entity on the picked point on the track
 AlignToVector(CarMesh,PickedNX(),PickedNY(),PickedNZ(),2,0.1) ;Aligns the CarMesh entity to the normal of the picked tri
 MoveEntity(CarMesh,0,0.5,0) ;Moves the CarMesh entity above the track	

 ;=====Add this part for a side view=====
 ;PositionEntity(Camera,EntityX(CarMesh),EntityY(CarMesh),-10)
 ;=======================================

 If(KeyDown(2)=True)
  Wireframe(True)
 ElseIf(KeyDown(2)=False)
  Wireframe(False)
 EndIf
	
 RenderWorld()
	
 Flip(True)

Wend
End


You should always be sure that the origine of your mesh is at the correct position in your modelisation software, else you will have all kinds of strange errors happening in Blitz3d.

Last edited 2012

Last edited 2012


Zeotrope(Posted 2012) [#10]
Thanks RemCoder. Pretty much what I wanted. Will post an update once I get my head around this stuff.

Appreciate your help
Cheers.


RemiD(Posted 2012) [#11]
I appreciated the advices of others when i started to learn Blitz3d, so if i can help sometimes that's cool :)

An important thing to learn from this is that for each mesh you load or create in Blitz3d there is an origine.
And this is this origine that represents your entity. The surfaces, triangles, vertices are child of this entity and they move, rotate with it.

In the code above, all functions used with CarMesh, refer to the origine of CarMesh. A kind of pivot.

This is an important concept to understand if you want to avoid strange behaviors in Blitz3d.

Last edited 2012


Zeotrope(Posted 2012) [#12]
Well thanks again.

Now the hard part begins. (putting the car code into a Type so that I can add multiple versions....ie: Opponents.) Will let you know how I go.

Last edited 2012