Jump to content


Photo

Vertapi. Api For Vertices, Cam And D3d_transforms


  • Please log in to reply
26 replies to this topic

#1 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 07 September 2009 - 09:35 AM

vertAPI

Thanks to Tepi and TheSnidr for the help

move/rotate/scale vertices using functions similar to GM's d3d_transform
Flawless camera rotation and position

Download vertAPI3.gmk V 3 beta2. Adds pitch yaw and roll (Airplane type or World relative) and a d3d_transform function to draw your models at the right orientation
** Note that your points added to the vert list do not yet rotate according to pitch yaw and roll, only the directional vectors are updated. Coming soon though

UPDATE:
Now you can match a 3d model transform to match vertapi with a single function


Download vertAPI.gmk GM7 merge file v1

Download vertAPI2.gmk V 2, Supports facing vector, right vector and up vector directly as per some of the documentaion in bottom of post. These vectors are useful for flawless camera movement and position as well as moving characters arround, See the vert_cam object




Users of API
3dStarMap

The idea is 3d transformation for points, or a series of points to match GM's d3d transform functions.

You see, the trouble with using gm's transformations to move/rotate/scale models (or any other stuff) is that you have no idea where, in x,y,z,rotx,roty,rotz the model finally ends up. Well you do (visually) but you have no data points to match and use in other function. For example, if I set the position to 10,0,0 then apply a scale on the x axis, say 15 then I rotate around the y axis, say 23 degrees, then rotate around the z axis, say 56 degrees, your basic model facing code or gun pointing. Where is that gun now in x,y,z,rotx,roty,rotz coords? Where is it’s tip?


example
d3d_transform_add_rotation_y( point_direction( 0, z, point_distance( x, y, other.x, other.y), other.z) + 90);
d3d_transform_add_rotation_z( point_direction( other.x, other.y, x, y));
d3d_transform_add_translation(( other.x + x) / 2 - off, (other.y + y) / 2, (other.z + z) / 2);
d3d_draw_cylinder( -2, -2, -dis, 2, 2, dis, global.jointtex, -2, -1, 0, 3);

Where are the edges of the cylinders now?

The solution is to mirror the calls d3d_transform calls with vert_transform calls

example:

Create:
model = d3d_model_create();
vert = vert_create();
COLOR = vert_create_extra_data(vert);

d3d_model_primitive_begin(model,pr_pointlist);

d3d_model_vertex_color(model,-5,-5,-5,c_blue,1);
d3d_model_vertex_color(model,-5,-5, 5,c_blue,1);
d3d_model_vertex_color(model,-5, 5,-5,c_yellow,1);
d3d_model_vertex_color(model,-5, 5, 5,c_yellow,1);
d3d_model_vertex_color(model, 5,-5,-5,c_lime,1);
d3d_model_vertex_color(model, 5,-5, 5,c_lime,1);
d3d_model_vertex_color(model, 5, 5,-5,c_orange,1);
d3d_model_vertex_color(model, 5, 5, 5,c_orange,1);
d3d_model_vertex_color(model, 0, 0, 0,c_red,1);
d3d_model_primitive_end(model);

vert_add(vert,-5,-5,-5); vert_add_extra_data(vert,COLOR,c_blue);
vert_add(vert,-5,-5, 5); vert_add_extra_data(vert,COLOR,c_blue);
vert_add(vert,-5, 5,-5); vert_add_extra_data(vert,COLOR,c_yellow);
vert_add(vert,-5, 5, 5); vert_add_extra_data(vert,COLOR,c_yellow);
vert_add(vert, 5,-5,-5); vert_add_extra_data(vert,COLOR,c_lime);
vert_add(vert, 5,-5, 5); vert_add_extra_data(vert,COLOR,c_lime);
vert_add(vert, 5, 5,-5); vert_add_extra_data(vert,COLOR,c_orange);
vert_add(vert, 5, 5, 5); vert_add_extra_data(vert,COLOR,c_orange);
vert_add(vert, 0, 0, 0); vert_add_extra_data(vert,COLOR,c_red);

Draw:
d3d_transform_set_identity();

	//transforms
	d3d_transform_add_rotation_x(a)
	d3d_transform_add_rotation_y(a)
	d3d_transform_add_rotation_z(a)
	d3d_transform_add_translation(40,30,0);
  
	//draw
	d3d_model_draw(model,0,0,0,-1);
	d3d_transform_set_identity();

	//mirror
	vert_transform_start(vert);
	
	//transforms
	vert_transform_add_rotation_x(vert, a)
	vert_transform_add_rotation_y(vert, a)
	vert_transform_add_rotation_z(vert, a)
	vert_transform_add_translation(vert,40,30,0);

	var s; s = vert_get_size(vert);
	//get the new position, draw in 2d (x/y axis only) for debugging.
	var i; i = 0;
	repeat(s)
	{
		draw_set_color(vert_get_extra_data(vert,COLOR,i));
		draw_point(vert_get_transformed_x(vert,i),vert_get_transformed_y(vert,i));
		i+=1;
	}

done:
d3d_model_destroy(model)
vert_destroy(vert);

Suggestions welcomed
Maybe adding vn so to rotate them at the same time as the vertices, but I decided not to add those in for speed, the function is the same as for the standard vertices rotation, you can add the extra lists in the create and do the transform in the proper functions if you want to also do VNs
I also added extra information support so you can add other lists in the container, for color or alpha
Facet functions, like cross product could be added. Though the system is vertices, it could be a good helper function.
I also added extra information support so you can add other lists in the vert container, such as color and alpha, vn, uv
Added normalizing functions;



Demo room:
Drop the test object in the room, removing the one there to see it in action.

hold space to see the GM d3d transfrom result to compare with the API result.
on the left is the result of the get_tranform_rotation (Wich is wrong and will not be fixed as it's totaly useless), in the middle is the vertices result.

Changes:
Added normize calculation, it is done on the transformed points. So if you want the normalized point of the original vertex, call vert_transform_start then perform the call. As stated I do not do the normals for the entire set, this is faster if you ocasionally need the normal of the point. But slower if you need it all the time.
Added rotation_axes
Fixed the destroy

Figuring Final Direction (From the top of my head)
**This is included as a default feature of Version 2. Version 2 has vectors (facing, right and up vectors) to figure of the final direction the rotation transforms (only) brought you.
To figure the final direction of an object (the facing direction), simply add a point 1,0,0 to your vertices. As the first or last point in your set. 1,0,0 is a point (in this case a vector) facing directly right. Since everything starts off facing right in GM, that is your model should be facing right (+x) in the modeler, just like your sprites, in 2d, should be facing right when image_angle is 0. Rotating this point in your set will give you the direction vector.

which, in terms of deviation, you can use to shoot a bullet in that directions simply using
hspeed = finalx*maxspeed;
vspeed = finaly*maxspeed;
zspeed = finalz*maxspeed;

The angle difference between the original point and the new point will be
a = radtodeg(arccos(median(-1,1,dot_product(1,0,0,finalx,finaly,finalz))));
*Note the median is used to avoid floating point errors which WILL occure as the dot potduct will ocasionaly yield a value like +-1.000000000001 which will cause arccos to blow up

and to rotate an object to this angle, say a bullet model that is too facing right originally, you would use
nx,ny,nz = normalized_cross_product(1, 0, 0, finalx, finaly, finalz);
d3d_transform_add_rotation_axis(nx,ny,nz,a);


Helper scripts
//cross_product(x1,y1,z1,x2,y2,z2,x3,y3,z3)
//also does the normalize
__x = (argument7-argument1)*(argument5-argument2)-(argument4-argument1)*(argument8-argument2);
__y = (argument8-argument2)*(argument3-argument0)-(argument5-argument2)*(argument6-argument0);
__z = (argument6-argument0)*(argument4-argument1)-(argument3-argument0)*(argument7-argument1);
//__x = (y3-y1)*(z2-z1)-(y2-y1)*(z3-z1);
//__y = (z3-z1)*(x2-x1)-(z2-z1)*(x3-x1);
//__z = (x3-x1)*(y2-y1)-(x2-x1)*(y3-y1);
var mag; mag=sqrt((__x*__x)+(__y*__y)+(__z*__z))
if(mag = 0)
{
__nx = __x
__ny = __y
__nz = __z
exit;
}
__nx = __x/mag
__ny = __y / mag
__nz = __z /mag

//dot_product(x1,y1,z1,x2,y2,z2,x3,y3,z3)
var Ax,Ay,Az,Bx,By,Bz;

Ax = argument0;
Ay = argument1;
Az = argument2;
Bx = argument3;
By = argument4;
Bz = argument5;
return Ax * Bx + Ay * By + Az * Bz

//normalize(x1,y1,z1)
//1 vector
var mag; mag=sqrt((argument0*argument0)+(argument1*argument1)+(argument2*argument2))
if(mag = 0)
{
__nx = argument0
__ny = argument1
__nz = argument2
exit;
}
__nx = argument0/mag
__ny = argument1/mag
__nz = argument2/mag

//normalize2(x1,y1,z1,x2,y2,z2)
//2 3d coords/vectors
var mag; mag=sqrt((argument0*argument0)+(argument1*argument1)+(argument2*argument2))
if(mag = 0)
{
__nx = argument0
__ny = argument1
__nz = argument2
exit;
}
__nx = argument0/mag
__ny = argument1/mag
__nz = argument2/mag


//vector(x1,y1,z1,x2,y2,z2)
//gets the deviation between 2 3d points and normalizes the result into __nx,__ny,__nz
__vx = argument3-argument0;
__vy = argument4-argument1;
__vz = argument5-argument2;

normalize(__vx,__vy,__vz);

Edited by icuurd12b42, 22 December 2011 - 11:19 PM.

  • 2

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#2 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 09 September 2009 - 05:25 AM

UPDATE:
Fixed divide by 0 in add_rotation_axis and optimised the code so not to make the same calculation twice for cos and sqrt
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#3 Jepie0

Jepie0

    GMC Member

  • GMC Member
  • 213 posts

Posted 26 September 2009 - 07:01 AM

THANKYOU icuurd12b42, your continually creating dll's and scripts that extend the possibility's of gamemaker. And without your fmod dll, 3d particle dll and now this vertAPI i would not be able to create 3d games that i imagine. Keep up the fantastic work, and its almost criminal that this particular topic has not been recieving mountains of praise and thankyous.

Cheers, Jepie0
  • 0

#4 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 September 2009 - 07:49 AM

Thanks, tepi was a big help too. For supporting my anoying little questions...

I added some comments in the post.

Edited by icuurd12b42, 26 September 2009 - 07:56 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#5 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 26 September 2009 - 08:24 AM

Pretty cool, but I don't understand what this is doing, I'll have to look at the code later.
  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#6 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 September 2009 - 08:41 AM

Pretty cool, but I don't understand what this is doing, I'll have to look at the code later.


I implemented this to move d3d model vertices in my 3dmodel animator. To match bone movements. But it's use is generic and can be used for various things. As I d3d transform the bones, I vert_transform the vertices attached to it. But you could use it to figure where the tip of a gun is and it's direction. in 2d or 3d.

The list sytem kindof obfuscates how it works though.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#7 brett14

brett14

    GMC Member

  • GMC Member
  • 1151 posts
  • Version:GM8

Posted 26 September 2009 - 09:01 AM

Ah; I see now. As for the use in your animator that's a good idea I had the exact same one lol! Like you said

we think alike


[MY IDEA WAS]
I was thinking of making an animator that would animate like movenow with body parts and a skeleton... Tween etc. However, when you save it, all the verticies of the body parts would be wrapped around the corresponding part and rotated [X,Y,Z] amount. Then would save every "frame" of the animation as a seperate model. Then I'd load each model into an array... we have a frame animation.

Edited by brett14, 26 September 2009 - 09:03 AM.

  • 0

P3DC V6.00 | Editor14 | Large 3D Terrain

GML programmer since 2005, C/C++ programmer since 2009, Java programmer since 2012


#8 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 26 September 2009 - 07:03 PM

Ah; I see now. As for the use in your animator that's a good idea I had the exact same one lol! Like you said

we think alike


[MY IDEA WAS]
I was thinking of making an animator that would animate like movenow with body parts and a skeleton... Tween etc. However, when you save it, all the verticies of the body parts would be wrapped around the corresponding part and rotated [X,Y,Z] amount. Then would save every "frame" of the animation as a seperate model. Then I'd load each model into an array... we have a frame animation.



I'll send you a copy of my animator...
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#9 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 06 October 2009 - 06:46 AM

Version2 is up... Added vector support, separated from the vertices, these vectors allow you to figure the facing, the right and the up direction to use with the camera, FMOD and other 3d tools and for moving characters arround and making them face the right direction.

Also added a few other helpers.

Still having trouble figuring the rotx,roty,rotz, though I added function to get roation axis data. tests reveal the information is flawed there too. So any good math guys, take a look at it and fix it if you like. I'm doing other things now. (Please inform me of the fix, if you do :rolleyes:)

Edited by icuurd12b42, 06 October 2009 - 06:47 AM.

  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#10 ean

ean

    GMC Member

  • New Member
  • 190 posts
  • Version:GM8

Posted 17 December 2011 - 08:16 PM

Is this faster or slower than the built in transformations? You mentioned it has plane pitch and roll for the camera, now does this mean it has this (no gimbal lock) for objects as well?
  • 0
VOTE FOR BUDDY ROEMER HE'S A STRAIGHTFORWARD, DOWN TO EARTH AMERICAN GUY WHO ISN'T PART OF THE BIGBROTHER CONSPIRACY

KILL NO LIVING THING

We have the worlds greatest scientist, engineers and politicians in this community with super fast computers


#11 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 17 December 2011 - 11:12 PM

try the demo
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#12 ean

ean

    GMC Member

  • New Member
  • 190 posts
  • Version:GM8

Posted 18 December 2011 - 01:10 AM

one thing i didn't think about, can you draw models with this?

I tried the demo, it didn't showcase quaternion models, there were a bunch of scripts, but you didn't mention anything in the original topic about whether or not you could, you said "useful only for a plane camera at the moment"
  • 0
VOTE FOR BUDDY ROEMER HE'S A STRAIGHTFORWARD, DOWN TO EARTH AMERICAN GUY WHO ISN'T PART OF THE BIGBROTHER CONSPIRACY

KILL NO LIVING THING

We have the worlds greatest scientist, engineers and politicians in this community with super fast computers


#13 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 18 December 2011 - 03:43 AM

No, unfortunately, that last minute added bit is only good for the camera. I asked around for some smartypants to finish it; convert to useful transforms, but no one volunteered.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#14 TheSnidr

TheSnidr

    Heavy metal viking dentist

  • GMC Elder
  • 3345 posts
  • Version:GM:Studio

Posted 18 December 2011 - 11:07 PM

That question disappeared under a ****load of something I can't recall. Would you mind explaining in detail what you needed once more? I'd love to help. If it's just rotating objects you need, search for slayer 64's quaternion scripts.
I'm currently writing a short article about quaternions the way I see them on my blog, I'll edit this post when I'm done

EDIT:
Writing it for people who haven't heard about quaternion math before was harder than I though. Gimme some time to make it readable

Edited by TheSnidr, 19 December 2011 - 11:54 PM.

  • 0

#15 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 19 December 2011 - 12:27 AM

That question disappeared under a ****load of something I can't recall. Would you mind explaining in detail what you needed once more? I'd love to help. If it's just rotating objects you need, search for slayer 64's quaternion scripts.
I'm currently writing a short article about quaternions the way I see them on my blog, I'll edit this post when I'm done



Well, I have a few vectors in there that follow the transforms. It seems to work fine, but the thing that is missing is a few functions to translate, probably using one or 2 of the vector values (maybe the facing vector and the right facing vectors), into useable d3d final transforms

rx = getRotX()
ry = getRotY()
rz = getRotZ()

so I can call
set identity
add rotation_x(rx)
add rotation_y(ry)
add rotation_z(rz)
set identity

It would be useful to rotate an airplane model for AI planes or your own plane when in chase view mode.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#16 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 19 December 2011 - 08:20 PM

one thing i didn't think about, can you draw models with this?

I tried the demo, it didn't showcase quaternion models, there were a bunch of scripts, but you didn't mention anything in the original topic about whether or not you could, you said "useful only for a plane camera at the moment"


It's in, re-download vertapi3

That question disappeared under a ****load of something I can't recall. Would you mind explaining in detail what you needed once more? I'd love to help. If it's just rotating objects you need, search for slayer 64's quaternion scripts.
I'm currently writing a short article about quaternions the way I see them on my blog, I'll edit this post when I'm done


Thanks for your help on this!!


UPDATE:
added vert_transform_model: use to rotate a model to match the direction vector; See PitchYawRolCamObj where I draw a cube in front of the camera.

copies TheSndr transform_add_rotation_matrix function... thanks man.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#17 ean

ean

    GMC Member

  • New Member
  • 190 posts
  • Version:GM8

Posted 20 December 2011 - 01:53 AM

one thing i didn't think about, can you draw models with this?

I tried the demo, it didn't showcase quaternion models, there were a bunch of scripts, but you didn't mention anything in the original topic about whether or not you could, you said "useful only for a plane camera at the moment"


It's in, re-download vertapi3

That question disappeared under a ****load of something I can't recall. Would you mind explaining in detail what you needed once more? I'd love to help. If it's just rotating objects you need, search for slayer 64's quaternion scripts.
I'm currently writing a short article about quaternions the way I see them on my blog, I'll edit this post when I'm done


Thanks for your help on this!!


UPDATE:
added vert_transform_model: use to rotate a model to match the direction vector; See PitchYawRolCamObj where I draw a cube in front of the camera.

copies TheSndr transform_add_rotation_matrix function... thanks man.


man that's cool, it can load .obj or gmmods right (doesn't matter which one.) i might use this if it gives me a speed increase.
  • 0
VOTE FOR BUDDY ROEMER HE'S A STRAIGHTFORWARD, DOWN TO EARTH AMERICAN GUY WHO ISN'T PART OF THE BIGBROTHER CONSPIRACY

KILL NO LIVING THING

We have the worlds greatest scientist, engineers and politicians in this community with super fast computers


#18 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 20 December 2011 - 04:07 AM

man that's cool, it can load .obj or gmmods right (doesn't matter which one.) i might use this if it gives me a speed increase.


You mean it should be able to rotate a model? sure. I have gmmodelfix (in my tools) to convert obj to d3d. You could load a plane, center the origins on it's mass, save as d3d... you got yourself a 3rd person view of a plane game.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#19 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 20 December 2011 - 09:50 PM

The last update does not work 100%... keep your panties on while I try to figure it out
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#20 DanRedux

DanRedux

    GMC Member

  • GMC Member
  • 1404 posts
  • Version:GM:Studio

Posted 21 December 2011 - 09:12 AM

What I would find extremely useful, possibly moreso than (scaling,translations,rotations)->position, is (scaling,translations,position)->rotations.

Say I have a lever and I click and hold on the tip. I would like to know what rotations I need to keep that vertex appearing where I move the mouse assuming the translation and scaling stays the same.

Clearly when I click the lever, I would create a "vert" at the mouse rays point of collision with the lever, then it would record the distance from the origin of the lever to that vert. I would then be able to feed a script the mouses new point of collision with the lever, and it would tell me what rotations I need to transform my lever with such at the vert I created appears at the new point of collision, aka, "clicking and dragging the lever down".

That example would be incredibly useful. Another example is Google Earth's dragging of the globe, where it grabs my mouse's initial point of collision, then rotates the Earth to maintain it.

This would be incredibly useful especially in 3D level editors, but also in that lever example, or as another example, a door. Grab the handle and physically swing it open. I believe this is called "anchoring" in Physics engines, where I would anchor the point-of-collision, and move it to the new point-of-collision with a cylinder around the origin of the door.

I understand that's incredibly complex. It is completely manageable for me to do the door handle swinging open, or if the lever was only rotated over 1 axis, but should it be a freely-rotating lever, like a globe, I am at a loss.
  • 0

#21 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 21 December 2011 - 05:58 PM

...


If you add some points (relative) in the vertices, they will have a new position after rotation. all you need is to check against those points. Say the door knob is at +10,+10,0 on the door... you add that point in the vertices list. It could be a single point and combined with a radius, you could do a ray trace and find the knob. Yes it's possible
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#22 DanRedux

DanRedux

    GMC Member

  • GMC Member
  • 1404 posts
  • Version:GM:Studio

Posted 21 December 2011 - 08:41 PM

But we wouldn't know the rotation.

I mean something like this cheap mockup I just made: >Download Door.gm81<
  • 0

#23 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 21 December 2011 - 10:51 PM

But we wouldn't know the rotation.

I mean something like this cheap mockup I just made: >Download Door.gm81<


Of course you would... that's why I wrote this

you have
d3d_transform_add_rotation_z(image_angle)
d3d_transform_add_translation(x,y,0)


you add
create
vert = vert_create();
vert_add(vert,10,10,0); //The knob position


you add to
d3d_transform_add_rotation_z(image_angle)
d3d_transform_add_translation(x,y,0)
vert_transform_start(vert);
vert_transform_add_rotation_z(vert,image_angle);
vert_transform_add_translation(x,y,0);

there you go... the vertex of your definition is transformed, to get it.

xx = vert_get_transformed_x(vert,0);
yy = vert_get_transformed_y(vert,0);
zz = vert_get_transformed_y(vert,0);

now you can do a line intersects sphere check from camx,camy,camz, in the direction vector (you can use another vert to figure the camera facing vector) against xx,yy,zz and a radius of your choosing.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#24 DanRedux

DanRedux

    GMC Member

  • GMC Member
  • 1404 posts
  • Version:GM:Studio

Posted 21 December 2011 - 11:23 PM

Yes, that still won't answer my question. That's a long winded way of doing a ray-sphere check for the nob.

I need to find out the angles the door should be transformed by such that the vert I define at the knob will be transformed to a position I give it (or as close as possible to that point).

A simple example is metal ball on a string pinned to a stick and someone has a very large magnet. The ball is the vert, the stick is the origin, and the string is the thing being transformed. I want to know what transformations are required to have the string point toward the magnet.

In my example, the door, I figure out where the door handle WILL be after it moves to my mouse position, then I use point_direction to find out where that is in relation to the door. Now I have a direction that I can rotate the door to, such that the knob appears right under my mouse.

What you're suggesting lets me find the location of the knob given the scaling, translation, and rotations. This is (scaling,translations,rotations)->position

What you need to include are functions to do other things using 3 known values, for example, given (scaling,translations,position), find rotations to match. It's all about solving for the 1 unknown value. Scaling, too, could be the unknown. You could know all the translations, position, and rotations of a vertex and need to know what to set the model scale to so that the vertex ends up right at the given position.

Another possible question would be actually quite important in a few cases- When you have scaling, position of the vert, and rotations of the model, but do not have the translations of the model. This would let you have a model that, no matter how much you rotate and scale it, you can still have a point be anchored from anywhere in the model to a certain position.

So here's one last attempt at explaining:
We have 4 variables: The set of rotations a model undergoes, the set of translations a model undergoes, the set of scales a model undergoes, and a vert position in that model's space (tip of the gun, for example).
I want to be able to leave one of those variables out and have it calculated. Right now, you leave out the vert position, and tell it the scaling, rotations, and translations, and it returns the vert position.

Ideally, you would be able to tell it the scaling, vert position, and translations of the model, and the Api would tell you the rotations required.

Again this is useful because in the door example above there is only rotating around the z axis. A fantastic example of how this would be useful would be an eyeball- You first, of course, find the position of the eye in the head using VertApi. Then you have a point in the real world- Your vert, defined. Then you define the scale and translations of the eye. Now it tells you the rotations that must be applied to that eye to have it facing directly at the vert.

If you could get that eye example going (an eye following a 'pixie' flying around the room), then I'll be satisfied.
  • 0

#25 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 22 December 2011 - 01:08 AM

I probably did not really understand still... But for the eye to pixie thing, not using the vert_api but the supplied helpers
//dealing with angles and distance
angle = point_direction(x,y,pixie.x,pixie.y);
zangle = point_direction_z(x,y,z,pixie.x,pixie.y,pixie.z);
distance = point_distance_3d(x,y,z,pixie.x,pixie.y,pixie.z);
//now because I'm lazy, short version of the GM d3d transforms
add rotation y (zangle) //or is it x
add rotation z (angle)
add translation x,y,z
draw the eye
set identity

Now the eye looks at the pixie

//To shoot it
//same lets use the vector helper
vert_vector(x,y,z,pixie.x,pixie.y,pixie.z);
//distance and direction vector
deltax = __vx;
deltay = __vy;
deltaz = __vz;
//direction vector (normalized vector, vert_normalize is called by vert_vector, you could have used vert_normalize2)
deltax = __nx;
deltay = __ny;
deltaz = __nz;

create a bullet at x,y,z to shoot it.
hspeed = deltax * maxspeed;
vspeed = deltay * maxspeed;
zspeed = deltaz * maxspeed;

Now say you have a gun who's tip is at 10,10,10
on create
vert = vert_create();
vert_add(vert,10,10,10); //The gun tip

step, follow the pixie
vert_transform_start(vert);
vert_transform_add_rotation_y (vert,zangle);
vert_transform_add_rotation_z (vert,angle);
vert_transform_add_translation (vert,x,y,z);

xx = vert_get_transformed_x(vert,0);
yy = vert_get_transformed_y(vert,0);
zz = vert_get_transformed_z(vert,0);

you could shoot from xx,yy,zz in the direction vector calculated above or the facing vector but you could miss the pixie, the gun being off to the side, so you can get a new vector from the tip to the pixie.

vert_normalize2(xx,yy,zz,pixie.x,pixie.y,pixie.z);


shoot a bullet at
hspeed = __nx * maxspeed;
vspeed = __ny * maxspeed;
zspeed = __nz * maxspeed;

//draw the gun
add rotation y (zangle) //or is it x
add rotation z (angle)
add translation x,y,z
draw the gun
set identity

The following is speculative:
The trouble with that is the bullet shoots crooked relative to the gun. I think you can adjust the gun though, and I think that is the foundation of your question. If you grab angle_difference from gmlscripts.com
http://www.gmlscript...ngle_difference

add more code
//reset
vert_transform_start(vert);
//re-transform using adjustments
angle2 = point_direction(xx,yy,pixie.x,pixie.y);
zangle2 = point_direction_z(xx,yy,zz,pixie.x,pixie.y,pixie.z);
vert_transform_add_rotation_y (vert,angle+angle_difference(zangle2,zangle));
vert_transform_add_rotation_z (vert,zangle+angle_difference(angle2,angle));
[edit] I dont think you need angle diffence... use angle2 and zangle2 as it for the transforms above
vert_transform_add_translation (vert,x,y,z);


here, in theory, you can use the code above or the facing vector to shoot from the tip. And you can re-grab the angles to draw the model.


I think that would do the trick, not 100% certain though.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#26 icuurd12b42

icuurd12b42

    Self Formed Sentient

  • GMC Elder
  • 18181 posts
  • Version:GM:Studio

Posted 22 December 2011 - 10:30 PM

UPDATE:

OK, so I fixed the d3d transform feature in vertapi3. the PitchYawRolCamObj draw code shows how it works.... The object supports plane flying mode or world relative mode and has a bonus swing weapon code which one user was having trouble with.


Thanks to TheSnidr for the really BIG help on this one. Actually, he did most it.
  • 0

gmcbanner.pnggmcbanner_tools.png

ICU Live Tutoring Through Slack or Skype | My Tools Page follow.png

I FRANTICALLY MADE MY 18000 POST TOPIC BEFORE MIKE ANNOUNCED A DELAY...
Now I'm squirming not to hit that reply button


#27 TheSnidr

TheSnidr

    Heavy metal viking dentist

  • GMC Elder
  • 3345 posts
  • Version:GM:Studio

Posted 22 December 2011 - 10:44 PM

UPDATE:

OK, so I fixed the d3d transform feature in vertapi3. the PitchYawRolCamObj draw code shows how it works.... The object supports plane flying mode or world relative mode and has a bonus swing weapon code which one user was having trouble with.


Thanks to TheSnidr for the really BIG help on this one. Actually, he did most it.

Aw, *blush* it was nothing ^^

Edited by TheSnidr, 22 December 2011 - 10:45 PM.

  • 0