Gamestudio Links
Zorro Links
Newest Posts
Trading Journey
by howardR. 04/28/24 09:55
basik85278
by basik85278. 04/28/24 08:56
Zorro Trader GPT
by TipmyPip. 04/27/24 13:50
Help with plotting multiple ZigZag
by M_D. 04/26/24 20:03
Data from CSV not parsed correctly
by jcl. 04/26/24 11:18
M1 Oversampling
by jcl. 04/26/24 11:12
Why Zorro supports up to 72 cores?
by jcl. 04/26/24 11:09
Eigenwerbung
by jcl. 04/26/24 11:08
AUM Magazine
Latest Screens
The Bible Game
A psychological thriller game
SHADOW (2014)
DEAD TASTE
Who's Online Now
1 registered members (blaurock), 752 guests, and 2 spiders.
Key: Admin, Global Mod, Mod
Newest Members
wandaluciaia, Mega_Rod, EternallyCurious, howardR, 11honza11
19049 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Page 2 of 2 1 2
Re: empty pointer error [Re: JerahYalyn] #450853
04/23/15 19:41
04/23/15 19:41

M
Malice
Unregistered
Malice
Unregistered
M



c_trace(......,IGNORE_ME | USE_POLYGON);
is my first idea. You're hitting the BBOX

Last edited by Malice; 04/23/15 19:42.
Re: empty pointer error [Re: JerahYalyn] #450854
04/23/15 19:43
04/23/15 19:43
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Try2 trace with
Code:
USE_POLYGON

flag set ( maybe activate POLYGON flag of your terrain / model ) and / or set the
Code:
SCAN_TEXTURE

flag in the c_trace command too.
But if iam right now, SCAN_TEXTURE is only need if u want2 add decals 4ex.

Greets

Last edited by rayp; 04/23/15 19:44. Reason: Ahhh didnt saw post from Malice :D

Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: empty pointer error [Re: rayp] #450858
04/23/15 20:05
04/23/15 20:05
Joined: Oct 2013
Posts: 31
JerahYalyn Offline OP
Newbie
JerahYalyn  Offline OP
Newbie

Joined: Oct 2013
Posts: 31
I actually use USE_POLYGON first and set terrain flags to POLYGON before changing my code since it still returns the sams result. In the image I provided, the hit position is actually flat in the terrain surface. Thd only thing I haven't tried is SCAN_TEXTURE. I shut the PC down after 2hours of trying.

Re: empty pointer error [Re: JerahYalyn] #450859
04/23/15 20:29
04/23/15 20:29

M
Malice
Unregistered
Malice
Unregistered
M



HI, Shouldn't you use vec_rotate(tempv,camera.pan) then c_trace. I think you are tracing straight down.

But I will stop guessing.

Re: empty pointer error [Re: ] #450861
04/23/15 21:29
04/23/15 21:29
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
You can trace, then loop through all terrain vertices and get closest one to the hit position, or you can use 'ent_getvertex' with 'hit.vertex', but it won't be accurate. Anyway if you want to access 'hit' parameters you need to use SCAN_TEXTURE, it won't work other ways. You don't need to use USE_POLYGON and POLYGON flag for terrain, it's not a model and it will work correctly without them! Terrain already has POLYGONAL hull, it doesn't have BBOX or elliposid hull.

I'll post working example tomorrow, I can't do that right now via my cellphone.

Problem with 'hit.vertex' returning zero in your example only related to SCAN_TEXTURE, you can't access 'hit' parameters without using it!

Best regards


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: empty pointer error [Re: 3run] #450863
04/23/15 21:49
04/23/15 21:49
Joined: Jul 2008
Posts: 2,107
Germany
rayp Offline

X
rayp  Offline

X

Joined: Jul 2008
Posts: 2,107
Germany
Quote:
HI, Shouldn't you use vec_rotate(tempv,camera.pan) then c_trace. I think you are tracing straight down.
Good idea. Maybe c_trace vectors are messed, right...did not look how he calculated the from and to vectors of the trace.

Try this ( just written not tested )
Code:
var hitvertex_global = 0; // global var holding last hit vertexnr
/*
// not sure if a terrain sets the YOU pointer when hit by c_trace. if not use something like this ( or hit.entity )
// and simply change "YOU" below to "terrainEnt"
ENTITY* terrainEnt;
action myTerrain_WED(){ // apply2 terrain in WED
   terrainEnt = me;
}
*/
action / function whatever(){
        ...
        ...
        hitvertex_global = 0;
	VECTOR _temp;
	_temp.x = mouse_pos.x;
	_temp.y = mouse_pos.y;
	_temp.z = 0;
	vec_set (target, _temp);
	target.z = 10000;
	vec_for_screen (_temp,  camera);
	vec_for_screen (target, camera);
        trace_mode = IGNORE_ME | IGNORE_PASSABLE;
	c_trace (_temp, target, trace_mode);
        if (HIT_TARGET){                        // sure "hit" pointer was set ( =hit something ) ?
           hitvertex_global = hit.vertex;        
           if (hitvertex_global && you){   // vertex? you?
              VECTOR _p;
              vec_for_vertex (_p, you, hitvertex_global);
              ent_create ("example.mdl", _p, NULL);
           }
         //same as ent_create ("bla.mdl", target, NULL); so theres no need4 vec_for_vertex in my quick example ^^
      }
        
}



Edit:
Besides...
After the c_trace check if you hit something ( entity 4ex ). Dont do:
Code:
c_trace ( ... );
you.health -= 10;

may Crash with "empty pointer". Do it like this instead
Code:
c_trace ( ... );
if (you) you.health -= 10;

In your case "hit" - may cause "empty pointer" error sometime, if i take a wild guess. ^^

Greets


Acknex umgibt uns...zwischen Dir, mir, dem Stein dort...
"Hey Griswold ... where u gonna put a tree that big ?"
1998 i married my loved wife ... Sheeva from Mortal Kombat, not Evil-Lyn as might have been expected
rayp.flags |= UNTOUCHABLE;
Re: empty pointer error [Re: rayp] #450867
04/24/15 04:15
04/24/15 04:15
Joined: Oct 2013
Posts: 31
JerahYalyn Offline OP
Newbie
JerahYalyn  Offline OP
Newbie

Joined: Oct 2013
Posts: 31
I think vec_rotate is not needed when using vec_for_screen. If I use it the ray tracer will rotate away from where I'm actually pointing. I tried your code rayp but I doesn't make any difference, there is still no hit.vertex returned.

@3run, Thanks for pointing that out to me man. I was able to fix it by using ent_nextvertex. I need to keep the GS manual open all the time for the list of all the functions.
new code.
Code:
var vert; //to store vertex index next to hit position
void camera_scan()
{
	VECTOR tempv,temp;
	while(1)
	{
		if(mouse_left) 
		{
			tempv.x = mouse_pos.x;
			tempv.y = mouse_pos.y;
			tempv.z = 2000;
			vec_for_screen(tempv,camera);
			c_trace(camera.x, tempv, IGNORE_ME | SCAN_TEXTURE);
			
			if(HIT_TARGET) //needed to prevent crashing when not hitting something :P
			{
				
				vert = ent_nextvertex(hit.entity,hit.x);
				vec_for_vertex(temp,hit.entity,vert);
				
				//for debugging, create a point and line from the hit  position to the nearest index
				draw_point3d(temp.x,vector(0,0,255),100,300);
				draw_point3d(vector(hit.x,hit.y,hit.z),vector(0,0,255),100,300);
				draw_line3d(vector(hit.x,hit.y,hit.z),vector(0,0,255),100);
				draw_line3d(temp.x,vector(0,0,255),100);
			}
		}
		wait(1);
	}
}



thanks for helping me out rayp and malice.
Now I just have to figure how to get all the the vertex near the hit position at a given radius without looping through each indices. I use Markus's real time terrain deforming library in A7 but it no longer work for A8 so I have to make my own function for terraform.

Last edited by JerahYalyn; 04/24/15 04:19.
Re: empty pointer error [Re: JerahYalyn] #450875
04/24/15 07:11
04/24/15 07:11
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
Originally Posted By: JerahYalyn
I think vec_rotate is not needed when using vec_for_screen. If I use it the ray tracer will rotate away from where I'm actually pointing. I tried your code rayp but I doesn't make any difference, there is still no hit.vertex returned.
I don't think 'vec_rotate' is needed for a line tracing from camera to the mouse position too. Cause mouse position will be infront of the camera anyway.

Originally Posted By: JerahYalyn
I actually use USE_POLYGON first and set terrain flags to POLYGON before changing my code since it still returns the sams result.
About USE_POLYGON and POLYGON flag for terrains, I couldn't post this via cellphone, but take a look at this:

So once again, I want to aware you to do not use such SLOW things when they aren't needed.

Originally Posted By: JerahYalyn
@3run, Thanks for pointing that out to me man. I was able to fix it by using ent_nextvertex. I need to keep the GS manual open all the time for the list of all the functions.

Now I just have to figure how to get all the the vertex near the hit position at a given radius without looping through each indices. I use Markus's real time terrain deforming library in A7 but it no longer work for A8 so I have to make my own function for terraform.
There was an example of terrain deforming somewhere around the forum:
Terrain Deform realTime
[Contest entry] DEFORM TERRAIN

Ask people in those threads, maybe someone still have any of those demos and can upload them for you.

About the working example I've made yesterday, here it is:
Code:
#define USE_FOR_LOOP

void main(){
	
	fps_max = 60;
	
	level_load("");
	
	BMAP* skinBmp = bmap_createblack(64, 64, 24);
	bmap_fill(skinBmp, COLOR_WHITE, NULL);
	
	
	ENTITY* terrainEnt = ent_createterrain(NULL, nullvector, 6, 6, 24);
	ent_setskin(terrainEnt, skinBmp, 0);
	
	d3d_lines = 3;
	
	vec_set(camera.x, vector(-180, 77, 166));
	vec_set(camera.pan, vector(339, -49, 0));
	
	mouse_mode = 4;
	
	VECTOR tempVec, vertexVec;
	
	var total_vertices = ent_vertices(terrainEnt);
	var hit_vertex = 0;
	
	int i = 0;
	
	while(terrainEnt){
		
		DEBUG_VAR(total_vertices, 10);
		DEBUG_VAR(hit_vertex, 40);
		
		vec_set(tempVec, mouse_dir3d);
		vec_scale(tempVec, 1000);
		vec_add(tempVec, mouse_pos3d);
		
		if(c_trace(mouse_pos3d, tempVec, IGNORE_PASSABLE + SCAN_TEXTURE) > 0){
			
			hit_vertex = hit.vertex;
			
			draw_point3d(hit.x, COLOR_RED, 100, 3);
		}
		
		if(HIT_TARGET && you && ent_type(you) == 4){
			
			#ifdef USE_FOR_LOOP
				
				for(i = 1; i < total_vertices + 1; i++){
					
					vec_for_vertex(vertexVec, terrainEnt, i);
					
					if(vec_dist(vertexVec.x, hit.x) < 10){
						
						CONTACT* contact = ent_getvertex(terrainEnt, NULL, i);
						contact.z += time_step;
						contact.v = NULL;
						ent_setvertex(terrainEnt, contact, i);					
						
						draw_point3d(vertexVec.x, COLOR_GREEN, 100, 5);
					}
				}
				
			#else
				
				CONTACT* contact = ent_getvertex(terrainEnt, NULL, hit_vertex);
				
				draw_point3d(contact.x, COLOR_GREEN, 100, 5);
				
				contact.z += time_step;
				contact.v = NULL;
				ent_setvertex(terrainEnt, contact, hit_vertex);					
				
			#endif
		}
		
		wait(1);
	}
}



If I remember correctly in most of those terrain deforming demos, they took 'hit' position and the nearest vertex, but then they create a square or circle around it, via some simple math calculations. I can't really help at this point, cause I've never made terrain deformation tools. You can also ask sivan if he is in a good mood, he might help you with this, since he is working on his MapEd for a few years now.

Originally Posted By: JerahYalyn
I use Markus's real time terrain deforming library in A7 but it no longer work for A8 so I have to make my own function for terraform.
BTW, why doesn't it work? Crashes?

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Re: empty pointer error [Re: 3run] #450877
04/24/15 09:03
04/24/15 09:03
Joined: Oct 2013
Posts: 31
JerahYalyn Offline OP
Newbie
JerahYalyn  Offline OP
Newbie

Joined: Oct 2013
Posts: 31
Thanks again man, exactly what I need. I`ll look in to NeoNaper's code to learn more about terraforming. But what I really need was the one Markus made.
The reason why it didn't work is because I used the A7 version of the DLL on A8 not knowing that there is a A8 version. Luckily Sivan uploaded the a mirror of the file.
I search the forum but it didn't showup for some reason. I also want to look into the Terrain Paint by Neo but the link is broken so I have to look somewhere else.


Last edited by JerahYalyn; 04/24/15 09:07.
Re: empty pointer error [Re: JerahYalyn] #450878
04/24/15 09:14
04/24/15 09:14
Joined: May 2009
Posts: 5,370
Caucasus
3run Offline
Senior Expert
3run  Offline
Senior Expert

Joined: May 2009
Posts: 5,370
Caucasus
I've looked through my HDD for those terrain deformation and painting demos (from NeoNeper), and luckely I've found them! In the archive you can also find 'saveLoad.c' file, with two function, one to save terrain vertex positions into the .txt file, and another one to load them back (this was done before save hmp file dll was created and contributed by Wjbender).

Best regards!


Looking for free stuff?? Take a look here: http://badcom.at.ua
Support me on: https://boosty.to/3rung
Page 2 of 2 1 2

Moderated by  HeelX, Lukas, rayp, Rei_Ayanami, Superku, Tobias, TWO, VeT 

Gamestudio download | chip programmers | Zorro platform | shop | Data Protection Policy

oP group Germany GmbH | Birkenstr. 25-27 | 63549 Ronneburg / Germany | info (at) opgroup.de

Powered by UBB.threads™ PHP Forum Software 7.7.1