| 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: |
| Matrix Transformations; need to rotate around any given axis | |
|---|---|
| Tweet Topic Started: Oct 1 2008, 06:42 AM (462 Views) | |
| EbTech | Oct 1 2008, 06:42 AM Post #1 |
|
Newbie
![]() ![]() ![]()
|
Hello, I'm new to this forum and to Ultimate 3D in general. Anyway I need some help with a particular matrix transformation. Basically, I want a way to replicate the effect of Game Maker's built-in d3d_transform_set_rotation_axis(xa,ya,za,angle) function, which rotates an object about a custom vector (i.e. axis) by a given angle. I'm only starting to learn basic linear algebra. Fortunately, I managed to Google up a formula for the general 4X4 matrix which should do the required transformation. My only problem is that I can't seem to find a function in U3D's documentation that would let me create this transformation matrix. In case anyone's wondering, I'm trying to make a realistic lightsaber duelling game. The incomplete version (without U3D) is posted here: Cybersword Duels By the way, do the default rotx, roty and rotz variables refer to Euler angles? And is there a way to rotate backgrounds (sky spheres) to give, for example, the illusion of wind? Edited by EbTech, Oct 1 2008, 06:44 AM.
|
![]() |
|
| MysteriXYZ | Oct 1 2008, 03:07 PM Post #2 |
|
Master Matrix Masher
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Hi EbTech, and welcome to the Ultimate 3D Community .To get that transformation matrix, you need to create a couple of others first and transform them with each other. Here's a script that returns a vector whose components you need to assign respectively to rotx/y/z of your object:
Yes, rotx (longitude) is the rotation angle in degrees around the world X-axis, roty (latitude) is the Euler angle around the Z-axis and rotz is the rotation performed around the Y-axis. The order in which the rotations are applied is as follows: 1) rotz 2) rotx 3) roty Also keep in mind that U3D uses a left-handed coordinate system, so to easily remember the positive sense of a rotation, just imagine that your left thumb points in the direction of the axis of rotation and curling your left fingers will mimic a positive rotation around that axis. Note also that the Y-axis is mirrored compared to the one in GM's Room Editor, which you can therefore interpret as a bottom-up view instead of a top-down one. You can use model objects to create custom backgrounds, which can be manipulated any way you want (see the end of this chapter of the documentation). |
| U3D is like candy; after extensive consumption, it's Best to brush. | |
![]() |
|
| EbTech | Oct 2 2008, 08:01 AM Post #3 |
|
Newbie
![]() ![]() ![]()
|
Wow, thank you so much! Ironically I have to prepare for my first linear algebra test on Friday, but after that I should finally be able to continue working on my game! My problem with Euler angles was that they lock up at the poles. I don't know whether this is related to gimbal lock, since I was only rotating around two of the axis, but either way it was making the lightsaber controls feel very unintuitive. Your script fixed this problem.
I've never used models before, but I'll have to give it a try eventually. Do you know of any good tutorials that explain how to make simple polygonal shapes? By that I mean, how would one draw polygons or ellipsoids out of triangles? I'm already familiar with the U3D functions that are used to set individual vertices and triangles after calling CreateEmptyMesh(). By the way, it doesn't seem like you ever used the RotAnglesVect parameter in your example. Was that intentionally left for me to implement?
Edited by EbTech, Oct 2 2008, 08:08 AM.
|
![]() |
|
| MysteriXYZ | Oct 2 2008, 07:28 PM Post #4 |
|
Master Matrix Masher
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
Glad to hear it .Although it's possible to create models from scratch with U3D, I wouldn't recommend it. Even something as simple as a sphere already requires a lot of thought (as you will see in the script below), and the most difficult part is setting the texture coordinates. If you wanted to project the texture in specific ways, this would become very complicated. Worst of all is that texture seams (where you want part of a texture to meet another part of a texture) require additional ("double") vertices. This is because one vertex can only have one pair of UV texture coordinates. So I would urge you to use a dedicated modelling program that you feel comfortable with, and export to one of the formats that U3D supports. Anyway, here's your ellipsoid, created entirely in U3D :
After calling this script in the Create Event of an object, you can set its texture like this: where TexID is the index you assigned to the texture when loading it with LoadTexture(<TextureFile>,TexID). It is used, as "argument0" in the following line near the end of the script: So if that parameter is the ID of an already previously created vector, that vector will contain the 3 angles needed to rotate your object. If the parameter is a negative number like -1, a new vector will be created and its ID returned by ComputeMatrixRotationAngles(...), which is then assigned to AngleVect, which is then returned by my script. So if you want to use an existing vector to retrieve the rotation angles, call my script as follows:
If you want to create a new vector for that, call it like this:
|
| U3D is like candy; after extensive consumption, it's Best to brush. | |
![]() |
|
| EbTech | Oct 2 2008, 09:33 PM Post #5 |
|
Newbie
![]() ![]() ![]()
|
Oh okay, that makes sense. Ouch! You're right, the ellipsoid script is pretty complicated! Still, I can definitely use this to make a simple wind effect (by rotating a cloudy sky sphere) and for thunder (by creating a partially transparent white sphere beneath the sky sphere). I also managed to build cylinders in U3D without too much trouble, which when combined with your rotation script and my own collision script (which works by calculating the distance between two line segments) end up making very realistic lightsabers! Okay well, I guess that's everything I needed for now. I might try Anim8or. My artistic skills are terrible, so I probably won't be making anything complicated. I might also add a two-player online mode to this game after it's done. GM's built-in mplay functions seem to be rather problematic, requiring port forwarding and updating shared data far too slowly for a high-speed action game. 39dll seems to be the most popular choice for online games... maybe I'll go learn that. In case you'd like to see how this game progresses, you can check the YoYoGames link in a few months. ![]() Edit: Do you know if Game Maker uses a similar algorithm to draw ellipsoids? I notice that yours only uses 2 radii (not that I want more, just curious.) Edited by EbTech, Oct 3 2008, 03:27 AM.
|
![]() |
|
| MysteriXYZ | Oct 3 2008, 03:52 PM Post #6 |
|
Master Matrix Masher
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]()
|
To be honest, I never really checked out GM's d3d functions, as it was obvious to me that it would be very hard to do anything worthwile with them. To add a third radius to my script is quite easy; replace RadiusH and RadiusV with RadiusX, RadiusY and RadiusZ which you then use like this:
Also replace both occurrences of "RadiusV" with "RadiusZ" and you're set.
I'll be sure to check it out . Good luck !
|
| U3D is like candy; after extensive consumption, it's Best to brush. | |
![]() |
|
| « Previous Topic · Questions about Ultimate 3D · Next Topic » |





![]](http://z1.ifrm.com/static/1/pip_r.png)



.
.
!
2:48 AM Jul 11