Rotate Normal about Itself

Started by
13 comments, last by daedalusd 23 years, 9 months ago
Thanks for the help WitchLord (as always), i know what your saying, and i personally prefer to figure things out myself if I can, but i''ve tried using the techniques you mentioned, and it just completely screws up You know how when you are trying to fix a problem for days, and you end up repeating things you''ve already tried ? Well i''m on the 6th time round them all i think If you could find it in your heart to provide a bit of source which I can disect and implement, i don''t want to completely rip it off, just to understand how it works for future use.

Thanks in advance



Adam "Nutz" Hoult
VB Gaming Central
Advertisement
I''ll see what I can dig up...

- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thanks, You da man This is the 4th time you've rescued me from completely dumping the whole thing hehe.

Adam "Nutz" Hoult
VB Gaming Central

Edited by - daedalusd on July 14, 2000 5:12:51 PM
Ok, here''s some code. It''s a few years old so I would probably not do it like this today but it worked then, and it should work for you too.

    void CFlatSurface::SetTextureData(CTextureContainer *pTexture, float fWidth, float fHeight, float fU, float fV, float fRotate, float fSkew){	D3DMATRIX dmtxRotate;	D3DVECTOR dvecUPrim, dvecVPrim;	D3DVECTOR *pdvecVertex;	if( m_pTextureContainer )		m_pTextureContainer->Release();	m_pTextureContainer = pTexture;	if( m_pTextureContainer )	{		m_pTextureContainer->Acquire();		m_bTextureApplied = TRUE;	}	else	{		m_bTextureApplied = FALSE;		return;	}	m_fTextureWidth = fWidth;	m_fTextureHeight = fHeight;	// Get the coordinate axises of the plane	if( fabs(m_dvecNormal.dvY) < (float)sqrt(0.5) )	{		// A vertical plane (almost)		m_dvecTextureUAxis = Normalize(CrossProduct(m_dvecNormal,Vector(0,1,0)));		m_dvecTextureVAxis = Normalize(CrossProduct(m_dvecNormal,m_dvecTextureUAxis));	}	else	{		// A horizontal plane		m_dvecTextureUAxis = Normalize(CrossProduct(m_dvecNormal,Vector(0,0,1)));		m_dvecTextureVAxis = Normalize(CrossProduct(m_dvecNormal,m_dvecTextureUAxis));	}	// Rotate the axises	dmtxRotate = RotationMatrix(m_dvecNormal, fRotate);	VectorMatrixMultiply(m_dvecTextureUAxis, m_dvecTextureUAxis, dmtxRotate);	VectorMatrixMultiply(m_dvecTextureVAxis, m_dvecTextureVAxis, dmtxRotate);	// Skew them	dmtxRotate = RotationMatrix(m_dvecNormal, fSkew);	VectorMatrixMultiply(m_dvecTextureUAxis, m_dvecTextureUAxis, dmtxRotate);	m_dvecTextureOrigo = Vector(0,0,0);	m_dvecTextureOrigo = m_dvecTextureOrigo - fU * (m_fTextureWidth*m_pTextureContainer->GetWidth()/g_wTextureSize) * m_dvecTextureUAxis;	m_dvecTextureOrigo = m_dvecTextureOrigo - fV * (m_fTextureHeight*m_pTextureContainer->GetHeight()/g_wTextureSize) * m_dvecTextureVAxis;	dvecUPrim = m_dvecTextureUAxis - DotProduct(m_dvecTextureUAxis, m_dvecTextureVAxis) * m_dvecTextureVAxis;	dvecVPrim = m_dvecTextureVAxis - DotProduct(m_dvecTextureVAxis, m_dvecTextureUAxis) * m_dvecTextureUAxis;	// Compute the texturecoordinates	pdvecVertex = m_pShell->GetVertexList();	for( int n = 0; n < m_iIndexCount; n++ )	{		m_pvtxIndex[n].fTU = DotProduct(pdvecVertex[m_pvtxIndex[n].wIndex]-m_dvecTextureOrigo,dvecUPrim)/			                 (dvecUPrim.dvX*dvecUPrim.dvX+dvecUPrim.dvY*dvecUPrim.dvY+dvecUPrim.dvZ*dvecUPrim.dvZ)/							 (m_fTextureWidth*m_pTextureContainer->GetWidth()/g_wTextureSize);		m_pvtxIndex[n].fTV = DotProduct(pdvecVertex[m_pvtxIndex[n].wIndex]-m_dvecTextureOrigo,dvecVPrim)/			                 (dvecVPrim.dvX*dvecVPrim.dvX+dvecVPrim.dvY*dvecVPrim.dvY+dvecVPrim.dvZ*dvecVPrim.dvZ)/							 (m_fTextureHeight*m_pTextureContainer->GetHeight()/g_wTextureSize);	}}    


- WitchLord

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

Thats it !!! I already had this !!, Syzygy mentioned the method earlier, the only thing which it didn''t have was the if (fabs(FNormal.y) < (float)sqrt(0.5)) etc, thank you both (credit where credits due, Syzygy did hit the nail on the head, but i didn''t figure i had to do the extra bit) and Especially witchlord, I can finally get on with the rest of my LIFE !! =)

Thanks, i''m forever in your debt hehehe .


Adam "Nutz" Hoult
VB Gaming Central

This topic is closed to new replies.

Advertisement