Angle between Old Vertex Normal New Vertex Normal

Blitz3D Forums/Blitz3D Programming/Angle between Old Vertex Normal New Vertex Normal

Spike314(Posted 2012) [#1]
Hi
Hope someone can help I'm using MDX vertex animation and I'm trying to parent an entity to a vertex which i have done using this:
Function AttachObject(ent.mdx,Model,vertex)
	Ent\Child[vertex] = Model
	EntityParent Model,ent\Mesh
	PositionEntity Model,VertexX(ent\surf,vertex),VertexY(ent\surf,vertex),VertexZ(ent\surf,vertex)
End Function


which works great for the position but I'm trying to rotate the entity to. I have been trying to use the old Vertex Normal with the New Vertex normal but it don't work.
like this:

				For v=0 To ent\verts-1
					If Ent\Child[v]<>0
						oldnx# =VertexNX(ent\surf,v)
						oldny# = VertexNy(ent\surf,v)
						oldnz# = VertexNz(ent\surf,v)
					EndIf
					vx#=(f1\vx[v]*(1-frametween))+(f2\vx[v]*frametween)
					vy#=(f1\vy[v]*(1-frametween))+(f2\vy[v]*frametween)
					vz#=(f1\vz[v]*(1-frametween))+(f2\vz[v]*frametween)
					nx#=(f1\nx[v]*(1-frametween))+(f2\nx[v]*frametween)
					ny#=(f1\ny[v]*(1-frametween))+(f2\ny[v]*frametween)
					nz#=(f1\nz[v]*(1-frametween))+(f2\nz[v]*frametween)
					
					If Ent\Child[v]<>0
						PositionEntity Ent\Child[v],vx,vy,vz
						dx# = nx + oldnx
						dy# = ny - oldny
						dz# = nz + oldnz
						;RotateEntity Ent\Child[v],-dy,0,0,1
						AlignToVector Ent\Child[v],dy,dx,dz,0
					EndIf
				        VertexCoords ent\surf,v,vx,vy,vz
					VertexNormal ent\surf,v,nx,ny,nz				
				Next


Last edited 2012


Yasha(Posted 2012) [#2]
Wow...

I think it's been at least two years since I last looked at that. I'd forgotten it existed!

I have to say, you could accomplish this much more easily using B3D models - then you could simply parent the entity in question to one of the animated mesh's bones and forget about it.

Is there a reason you chose MDX? Because unless you desperately need to be able to cast shadows onto the animated mesh (and even then... you can do that with stencils) it's slower and less efficient than the other two main Blitz3D options.

As for the normals issue - is this a model you've made yourself, and if so, how? Because some artists may not move the normals in a predictable smooth fashion (if they always did, we wouldn't need to have it as a setting), and therefore you might not be able to rely on it to move in a predictable way relative to the mesh.

Come to think of it, you shouldn't really need to store the old normals for this - if you AlignToVector of the new normal only, it will turn it relative to the vector of the old normal (I think..?). If you don't want it facing the normal vector, you can then apply a TurnEntity of a constant amount to make it face in the direction you actually want (and you can work out how much this is by measuring its actual orientation).

I think.... there must be a better way of doing this though. What is it you're actually trying to create?


Spike314(Posted 2012) [#3]
I've Converted it to Xors3d and it seems faster then xors animation system. if i have 100 bone animations I get 25-26 FPS but with the MDX system I get 45-46 FPS and this is without using Shaders as I'm not very good at them also your MDX system loads faster to.

I'm using native blitz3d as prototyping the system until im ready to fully convert and add it to my project.

I tried using just the new normals but no look.


Kryzon(Posted 2012) [#4]
VertexX, Y and Z and VertexNX, NY and NZ return values that are local to the mesh the surface belongs to.
If that first part is working as planned, it's by a happy accident - maybe the mesh you're testing is centered at the world's origin? this means both the local and global values are the same.
It probably won't work in the middle of a game full of characters scattered throughout an environment.

You should transform the local positions\directions into global values before using them in transformations.

For instance, the way it should be:
Function AttachObject(ent.mdx,Model,vertex)
	Ent\Child[vertex] = Model
	EntityParent Model,ent\Mesh

	Local newX#,newY#,newZ#
	newX = VertexX(ent\surf,vertex)
	newY = VertexY(ent\surf,vertex)
	newZ = VertexZ(ent\surf,vertex)
	TFormPoint newX, newY, newZ, ent\Mesh, 0
	PositionEntity Model, TFormedX(), TFormedY(), TFormedZ(), True
End Function
And....
If Ent\Child[v]<>0
	TFormPoint(vx,vy,vz,Ent\Mesh,0)
	PositionEntity Ent\Child[v],TFormedX(),TFormedY(),TFormedZ()
	dx# = nx + oldnx
	dy# = ny - oldny
	dz# = nz + oldnz
	TFormVector(dx,dy,dz,Ent\Mesh,0)
	AlignToVector Ent\Child[v],TFormedX(),TFormedY(),TFormedZ(),0
EndIf

Try these out and tell me what happens.

Last edited 2012


Spike314(Posted 2012) [#5]
it's just the pitch isn't aligning right the yaw seems fine