- Joined
- Mar 28, 2008
- Messages
- 2,666
- Reaction score
- 795
- Points
- 128
I wanted to contibute a little bit to this GREAT client and decided to implement a small feature that is still missing: ShowGrapplePoints
Thanks, That's a really good news. I'll greatly appriciate that.
Can you give me a hint on how to render the Meshes?
Am I on the right track?
Or should I have used some other technique?
It looks good. But there is something odd about the arrow vertices. In a non-indexed mesh the vertices should come in a groups of three and there is no need to place the color in the vertices.
There are two possibilities.
1. Create an arrow using NTVERTEX declaration and existing shaders.
2. Create an arrow using D3DVECTOR declaration and write a new shader for it.
In this example I have selected the option 2 because the first one would need a normal and texture coordinates for the vertices and also a texture would need to be attached into the pipeline to allow existing shaders to work.
My computer is currently a bit broken so I haven't been able to test the code. So, It may contain some errors.
Here is a code example for a rendering routine:
Code:
[SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] D3D9Effect::RenderArrow(OBJHANDLE hObj, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] VECTOR3 *ofs, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] size, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] D3DXCOLOR *pColor)
{
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] D3DVECTOR arrow[9] = {
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Head
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{0.0, 0.0, 0.0},
{0.0,-1.0, 1.0},
{0.0, 1.0, 1.0},
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Body first triangle
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{0.0,-0.5, 1.0},
{0.0,-0.5, 2.0},
{0.0, 0.5, 2.0},
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Body second triangle
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]{0.0,-0.5, 1.0},
{0.0, 0.5, 2.0},
{0.0, 0.5, 1.0}
};
MATRIX3 grot;
VECTOR3 camp, gpos;
oapiGetRotationMatrix(hObj, &grot);
oapiGetGlobalPos(hObj, &gpos);
oapiCameraGlobalPos(&camp);
VECTOR3 pos = gpos - camp;
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]if[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] (ofs) pos += mul (grot, *ofs);
D3DXMATRIX W;
D3DXVECTOR3 vPos([/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](pos.x), [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](pos.y), [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](pos.z));
D3DXVECTOR3 vCam;
D3DXVec3Normalize(&vCam, &vPos);
D3DMAT_CreateX_Billboard(&vCam, &vPos, size, &W); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Create a billboard world matrix to face the X-axis towards camera
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]UINT numPasses = 0;
HR(pDev->SetVertexDeclaration(pPositionDecl)); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Position only vertex decleration
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]HR(FX->SetTechnique(eArrowTech)); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Use arror shader
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]HR(FX->SetValue(eColor, pColor, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](D3DXCOLOR))); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Setup arrow color
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]HR(FX->SetMatrix(eW, &W));
HR(FX->Begin(&numPasses, D3DXFX_DONOTSAVESTATE));
HR(FX->BeginPass(0));
HR(pDev->DrawPrimitiveUP(D3DPT_TRIANGLELIST, 3, &arrow, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]sizeof[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2](D3DVECTOR))); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Draw 3 triangles un-indexed
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]HR(FX->EndPass());
HR(FX->End());
gc->GetStats()->Draw++; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Increment rendering statistics counter
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]}
[/SIZE]
Here are a few other changes needed to create a new shader:
Code:
[SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// ==== These lines go into the D3D9Effect.cpp ====
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]D3DXHANDLE D3D9Effect::eArrowTech = 0;
eArrowTech = FX->GetTechniqueByName([/SIZE][SIZE=2][COLOR=#a31515][SIZE=2][COLOR=#a31515]"ArrowTech"[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]);
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// ==== These lines go into the D3D9Effect.h ====
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]void[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] RenderArrow(OBJHANDLE hObj, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] VECTOR3 *ofs, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]float[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] size, [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]const[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] D3DXCOLOR *pColor);
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]static[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] D3DXHANDLE eArrowTech;
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// ==== These lines go into the D3D9Client.fx ====
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]BShadowVS ArrowTechVS(float3 posL : POSITION0)
{
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Zero output.
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]BShadowVS outVS = (BShadowVS)0;
float3 posW = mul(float4(posL, 1.0f), gW).xyz; [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Apply world transformation matrix
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]outVS.posH = mul(float4(posW, 1.0f), gVP); [/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// Apply view projection matrix
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2][/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] outVS;
}
float4 ArrowTechPS(BShadowVS frg) : COLOR
{
[/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]return[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2] gColor;
}
[/SIZE][SIZE=2][COLOR=#008000][SIZE=2][COLOR=#008000]// This is used for rendering beacons ------------------------------------------
//
[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2]technique ArrowTech
{
pass P0
{
vertexShader = compile VS_MOD ArrowTechVS();
pixelShader = compile PS_MOD ArrowTechPS();
AlphaBlendEnable = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
BlendOp = Add;
SrcBlend = SrcAlpha;
DestBlend = InvSrcAlpha;
ZWriteEnable = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]false[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
ZEnable = [/SIZE][SIZE=2][COLOR=#0000ff][SIZE=2][COLOR=#0000ff]true[/COLOR][/SIZE][/COLOR][/SIZE][SIZE=2];
}
}
[/SIZE]
To use the code you need to pass a vessel handle to the routine.
hVessel = vessel->GetHandle();
D3D9Effect::RenderArrow(hVessel, &pos, (float)size, &D3DCOLOR(0,0,1));
---------- Post added at 12:12 ---------- Previous post was at 11:58 ----------
Sorry, I supose the last line should be like this
D3D9Effect::RenderArrow(hVessel, &pos, (float)size, &D3DXCOLOR(0,0,1,1));