1 registered members (AbrahamR),
717
guests, and 4
spiders. |
Key:
Admin,
Global Mod,
Mod
|
|
|
So simple...
#245102
01/08/09 12:41
01/08/09 12:41
|
Joined: Feb 2008
Posts: 337
Vadim647
OP
Senior Member
|
OP
Senior Member
Joined: Feb 2008
Posts: 337
|
I was wondering around, and thought about a simple yet very usefull function: draw_triangle(VECTOR vertex1,VECTOR vertex2,VECTOR vertex3,BMAP texture, VECTOR texturepos1, VECTOR texturepos2, VECTOR texturepos3); It should do a very simple thing - draw a textured triangle. Also (optional), add a function to change color tilting and alpha for that (like draw_triangle_color(VECTOR color,var alpha); Possible usages: * Dynamic terrain\waves\etc * Object trails * All variety of spells and stuff * ... (I'm not in mood to think of other usage ways, but I'm pretty sure that this one would be a awesome addition to engine (esp. if you will update LiteC download with it )
|
|
|
Re: So simple...
[Re: FBL]
#245293
01/09/09 09:01
01/09/09 09:01
|
Joined: May 2002
Posts: 7,441
ventilator
Senior Expert
|
Senior Expert
Joined: May 2002
Posts: 7,441
|
yes! i noticed in the manual that with ent_create(NULL, nullvector, NULL); it's possible to create dummy entities. it would be cool if some shape like BOX, CONE, CUBE,... could be specified for them.
|
|
|
Re: So simple...
[Re: Vadim647]
#245300
01/09/09 10:01
01/09/09 10:01
|
Joined: Aug 2000
Posts: 1,140 Baunatal, Germany
Tobias
Moderator
|
Moderator
Joined: Aug 2000
Posts: 1,140
Baunatal, Germany
|
I can write a draw_triangle function in DirectX, it is no so difficult, there is also an example already in the samples folder. But the problem is Triangles can not be used for drawing bodies because they have no necessary features such as materials, normals, lighting, collision detection, clipping and so on. #include <acknex.h>
#include <default.c>
#include <d3d9.h>
// define a 2D vertex struct
typedef struct VERTEX_FLAT {
float x,y,z;
float rhw;
D3DCOLOR color;
} VERTEX_FLAT;
#define D3DFVF_FLAT (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)
function main()
{
vec_set(screen_color,vector(1,1,1)); // black nontransparent screen
// define and preset the triangle
VERTEX_FLAT vf[3];
vf[0].color = 0xFFFF0000; // the red corner
vf[1].color = 0xFF0000FF; // the blue corner
vf[2].color = 0xFF00FF00; // the green corner
vf[0].rhw = vf[1].rhw = vf[2].rhw = 1.0; // no perspective
// define three corner vectors
VECTOR v[3];
vec_set(v[0],vector(100,100,0));
vec_set(v[1],vector(400,100,0));
vec_set(v[2],vector(400,400,0));
// define the rotation center
VECTOR center;
vec_set(center,vector(250,250,0));
wait(1); //wait until the D3D Device is opened after the first frame
// draw a red/blue/green rotating triangle
var angle = 0;
while(1)
{
// rotate the corner vectors
int i;
for (i=0; i<3; i++)
{
VECTOR vTemp;
vec_diff(vTemp,v[i],center);
vec_rotate(vTemp,vector(angle,0,0));
vec_add(vTemp,center);
vf[i].x = vTemp.x;
vf[i].y = vTemp.y;
vf[i].z = 0;
}
angle += 10*time_step;
// open the scene and get the active D3D device
LPDIRECT3DDEVICE9 pd3dDev = (LPDIRECT3DDEVICE9)draw_begin();
if (!pd3dDev) return;
// set some render and stage states
pd3dDev->SetRenderState(D3DRS_ALPHABLENDENABLE,FALSE);
pd3dDev->SetTextureStageState(0,D3DTSS_COLORARG2,D3DTA_DIFFUSE);
pd3dDev->SetTextureStageState(0,D3DTSS_COLOROP,D3DTOP_SELECTARG2);
// now draw the triangle
pd3dDev->SetFVF(D3DFVF_FLAT);
pd3dDev->DrawPrimitiveUP(D3DPT_TRIANGLEFAN,1,(LPVOID)vf,sizeof(VERTEX_FLAT));
wait(1);
}
}
|
|
|
Re: So simple...
[Re: Tobias]
#245306
01/09/09 10:45
01/09/09 10:45
|
Joined: Oct 2004
Posts: 4,134 Netherlands
Joozey
Expert
|
Expert
Joined: Oct 2004
Posts: 4,134
Netherlands
|
But the problem is Triangles can not be used for drawing bodies because they have no necessary features such as materials, normals, lighting, collision detection, clipping and so on. I drawed a mesh object with diffuse colors and several triangles with DX in 3d space, I suppose that's a body? Creating a box isn't really that hard.
Last edited by Joozey; 01/09/09 10:46.
Click and join the 3dgs irc community! Room: #3dgs
|
|
|
|