So simple...

Posted By: Vadim647

So simple... - 01/08/09 12:41

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 smile )
Posted By: Cowabanga

Re: So simple... - 01/08/09 13:54

Yeah... It would be a awesome addition to engine. please JCL put this awesome function!
Posted By: jcl

Re: So simple... - 01/08/09 14:00

Hmm, quads are normally needed more often than triangles, but I'll think about it.
Posted By: ello

Re: So simple... - 01/08/09 14:14

in that case, maybe you can add quads, too smile
Posted By: FBL

Re: So simple... - 01/09/09 08:55

And basic bodies like boxes, cyliners, cones and cubes smile
Posted By: ventilator

Re: So simple... - 01/09/09 09:01

yes! smile

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.
Posted By: Vadim647

Re: So simple... - 01/09/09 09:04

Any basic body can be drawn with some poly\triangle functions. If the feature will be added, I'll provide functions for those smile
Posted By: Tobias

Re: So simple... - 01/09/09 10:01

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.

Code:
#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);
	}
}

Posted By: Joozey

Re: So simple... - 01/09/09 10:45

Quote:
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.
Posted By: FBL

Re: So simple... - 01/09/09 11:16

Well for 3D objects it would be cool to have them as real entities, just as proposed by ventilator.
Posted By: Joozey

Re: So simple... - 01/09/09 11:53

Like:

Quote:
ent_getmesh(ENTITY* ent,var num,var lod);
ent_setmesh(ENTITY* ent,void* mesh,var num,var lod);
Returns or sets the DirectX mesh of the given model or terrain entity.



?
Posted By: ventilator

Re: So simple... - 01/09/09 12:03

the problem is that it doesn't seem to be possible to set the mesh of an empty dummy entity.
Posted By: FBL

Re: So simple... - 01/09/09 12:47

Originally Posted By: Joozey
Like:

Quote:
ent_getmesh(ENTITY* ent,var num,var lod);
ent_setmesh(ENTITY* ent,void* mesh,var num,var lod);
Returns or sets the DirectX mesh of the given model or terrain entity.



?


That's not the point.
I want to create primitives on the fly (like in Darkbasic) and not have to learn how the mesh is stored internally and then assebmles by hand...
Posted By: FBL

Re: So simple... - 01/09/09 12:51

Quote:

V7.67 - in development
A predefined primitive cube, sphere, and sprite entity can now be created with ent_create.



Now that was fast O_o
Posted By: Vadim647

Re: So simple... - 01/09/09 13:41

...
And what about the polygon drawing...?
Posted By: Quad

Re: So simple... - 01/09/09 13:48

so we can go 3d easily on winter contest!
Posted By: Cowabanga

Re: So simple... - 01/09/09 16:59

Originally Posted By: Quadraxas
so we can go 3d easily on winter contest!


LOL! yeah!
Posted By: FBL

Re: So simple... - 01/09/09 17:58

Well it's not implemented for the current public beta. I guess we won't see it soon enough smile
Posted By: Vadim647

Re: So simple... - 01/09/09 20:02

I wish I'd be able to see\download those beta's...
Posted By: Crypton

Re: So simple... - 01/09/09 20:11

Just a thought.
When there is a possibility to create shaped meshes / entities, then there would be possibility to manipulate their surface too
f.i ent_flip_mesh ; ent_color etc.
flip_mesh has some advantages. For example entities react to fog etc. So when creating an sphere mesh and flipping it, there is a way to fill room with visible fog without making a huge map entity cube. useful for open air games, flying or smth, that needs this atmospheric look, probably better to make visible skybox too that is blended with the fog... although when no image is possible then with ent_color you could color the entity.

Cheers!
© 2024 lite-C Forums