Welcome Guest [Log In] [Register]
We hope you enjoy your visit.


You're currently viewing the Ultimate 3D Community as a guest. This means that you can only read posts, but can not create posts or topics by yourself. To be able to post you need to register. Then you can participate in the community active and use many member-only features such as customizing your profile, sending personal messages, and voting in polls. Registration is simple, fast, and completely free.

Join our community!

If you are already a member please log in to your account to access all of our features:

Username:   Password:
Add Reply
Matrix/Vector Help
Topic Started: Nov 29 2007, 09:37 AM (328 Views)
Linkin
Member Avatar
Forum God
[ *  *  *  *  *  * ]
Ok for my weapon i want to be able to set a XOffset and a YOffset for my weapon, so far i have this.

Weapon Creation Event

Code:
 

XVectOf=CreateVector(-1,Camera.x-x,0,0);
YVectOf=CreateVector(-1,0,Camera.y-y,0);
XFact=2;
YFact=.05;
CalculateVectorScalarProduct(XVectOf,XVectOf,XFact);
CalculateVectorScalarProduct(YVectOf,YVectOf,YFact);


Step Event
Code:
 

var XVect,YVect,RotMatr;
RotMatr=CreateRotationMatrix(-1,Camera.rotx,Camera.roty,Camera.rotz);
//rotate the offset vector to align it with the Camera
XVect=TransformVector(-1,XVectOf,RotMatr);
YVect=TransformVector(-1,YVectOf,RotMatr);
//place the model at the coordinates of the rotated vector
x=Camera.x+GetVector(XVect,1);
y=Camera.y+GetVector(YVect,2);
z=Camera.z+Camera.height-GetVector(Vect,3);
//set the model's orientation to that of the Camera
rotx=-Camera.rotx;
roty=Camera.roty-180;
rotz=Camera.rotz;

ReleaseVector(XVect);
ReleaseVector(YVect);
ReleaseMatrix(RotMatr);


Any Ideas?

Edit: O yea ive looked at examples and things but still don't realy get it
Posted Image
Want something done in Photoshop, make a request Here

Formerly known as DS-Development.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
First of all, you can combine those 2 offset vectors into a single one, multiplying its components directly with the scaling factors.
Second, the offset vector should point from the camera to the weapon, so you need to subtract the camera location from the weapon location. An easy way to remember what a vector is pointing at when defining it by subtracting one location (A) from another (B ), i.e. B-A, is to ask yourself: "Who started it all?", to which the answer here would be: "B did!", accusingly pointing your finger at B (B is the first term in "B-A"), so the offset vector would point from A to B.

So the code in the Weapon Creation Event can be reduced to this:
Code:
 
VectOf=CreateVector(-1,(x-Camera.x)*2,(y-Camera.y)*.05,0);


Then the code in the Step Event becomes this:
Code:
 
var Vect,RotMatr;

RotMatr=CreateRotationMatrix(-1,Camera.rotx,Camera.roty,Camera.rotz);
//rotate the offset vector to align it with the Camera
Vect=TransformVector(-1,VectOf,RotMatr);
//place the model at the coordinates of the rotated vector
x=Camera.x+GetVector(Vect,1);
y=Camera.y+GetVector(Vect,2);
z=Camera.z+Camera.height-GetVector(Vect,3);
//set the model's orientation to that of the Camera
rotx=-Camera.rotx;
roty=Camera.roty-180;
rotz=Camera.rotz;

ReleaseVector(Vect);
ReleaseMatrix(RotMatr);


Let me know if it works.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
Linkin
Member Avatar
Forum God
[ *  *  *  *  *  * ]
Very Nice, Man you truly are A Matix/Vector Guru lol

Thanks :)
Posted Image
Want something done in Photoshop, make a request Here

Formerly known as DS-Development.
Offline Profile Quote Post Goto Top
 
Linkin
Member Avatar
Forum God
[ *  *  *  *  *  * ]
Ok so thats working all awsomly on the weapon but when i use the same code to try and align the MuzzleFlash to the tip of the gun it does not work??

Why would it work on one object and not work on another? Could it be because the Muzzle Flash is a billboard?
Posted Image
Want something done in Photoshop, make a request Here

Formerly known as DS-Development.
Offline Profile Quote Post Goto Top
 
MysteriXYZ
Member Avatar
Master Matrix Masher
[ *  *  *  *  *  * ]
To place the Muzzle Flash at the tip of the gun, you'll need to know the distance from the gun origin to its tip, and add that to the y-component of VectOf (assuming that this vector gets defined when the camera is supposed to be pointing in the default, positive Y-direction, with rotx/y/z=0).
You may also need to change the originx and originy variables to better position the Muzzle Flash.

If that doesn't solve it, I'll need to see some code and/or a more precise description of what exactly is happening.
U3D is like candy; after extensive consumption, it's Best to brush.
Offline Profile Quote Post Goto Top
 
Linkin
Member Avatar
Forum God
[ *  *  *  *  *  * ]
Nvm i solved it i just changed it to this
Code:
 
VectOf=CreateVector(-1,(x-pl_ak47.x-.05),(y-pl_ak47.y-6),.4);


Thanks
Posted Image
Want something done in Photoshop, make a request Here

Formerly known as DS-Development.
Offline Profile Quote Post Goto Top
 
« Previous Topic · Questions about Ultimate 3D · Next Topic »
Add Reply