≡
Products
▼
Support
▼
Company
▼
Forum
Ambiera Forum
Discussions, Help and Support.
Create a new account
,
Search
, or Login:
Create reply in
How do I get a (sort of) absolute vertex position?
Posted by:
(you are not logged in)
Enter the missing letter in: "Internatio?al"
(you are not logged in)
Text:
[quote][b][/b] wrote: So, after (obviously) having no replies, I tried to do... At least something. I found a few articles about rotational matrixes, and those articles had some... Formulas. Despite the fact that I wrote the exact same formulas in my code, it gave me terrible... TERRIBLE results. Simple cube, that I've used for testing purposes, deformed in various shapes... except for cube, if the angle wasn't 0 on every axis. I tried to rewrite some stuff in formulas, but to no success. One of my thoughts is that it kinda happens because in CopperCube Y-axis goes up instead of going to side, so this might be a reason. Now I only left the X rotation thing, and it still works terribly: the mesh, rotated by 90 degrees gave incredibly different rotation (143 degrees), I don't know how it works. Same goes to other degrees, of course. Here's the formulas: [img]https://i.postimg.cc/2yX4S4wk/image.png[/img] (Things on russian translates as "By X axis", "By Y axis" and "By Z axis"). And here's the script that I wrote: [code]function RotationCorrection () { var Node = editorGetSelectedSceneNode (); var Buffers = ccbGetSceneNodeMeshBufferCount (Node); var Rot = ccbGetSceneNodeProperty (Node, "Rotation"); var Array = [Rot.x, Rot.y, Rot.z]; //Normalizing rotation for (var Axis = 0; Axis < 3; ++Axis) { if (Array [Axis] > 360) { do { Array [Axis] -= 360; } while (Array [Axis] > 360); } if (Array [Axis] < 0) { do { Array [Axis] += 360; } while (Array [Axis] < 0); } } Rot.x = Array [0]; Rot.y = Array [1]; Rot.z = Array [2]; ccbSetSceneNodeProperty (Node, "Rotation", 0, 0, 0); var sin = Math.sin; var cos = Math.cos; if (Buffers == 0) alert ("Ayo, what the ****?"); else { for (var b = 0; b < Buffers; ++b) { var Verticies = ccbGetMeshBufferVertexCount (Node, b); for (var v = 0; v < Verticies; ++v) { var NewPos = ccbGetMeshBufferVertexPosition (Node, b, v); var Pos = ccbGetMeshBufferVertexPosition (Node, b, v); //Rotating by X axis only NewPos.y = Pos.y * cos(Rot.x) + Pos.z * sin(Rot.x); NewPos.z = -Pos.y * sin(Rot.x) + Pos.z * cos(Rot.x); ccbSetMeshBufferVertexPosition (Node, b, v, NewPos); } } ccbUpdateSceneNodeBoundingBox (Node); } var Rot = ccbGetSceneNodeProperty (Node, "Rotation"); ccbSetSceneNodeProperty (Node, "Rotation", 0, 0, 0); var sin = Math.sin; var cos = Math.cos; } editorRegisterMenuEntry ("RotationCorrection();", "Freeze rotation of object");[/code] I am sure that the script might be bad, but at least that's my first plugin for CopperCube. If you understand something about what's wrong, can you please tell me where did I screwed up.[/quote]
Possible Codes
Feature
Code
Link
[url] www.example.com [/url]
Bold
[b]bold text[/b]
Image
[img]http://www.example.com/image.jpg[/img]
Quote
[quote]quoted text[/quote]
Code
[code]source code[/code]
Emoticons
Copyright© Ambiera e.U. all rights reserved.
Privacy Policy | Terms and Conditions | Imprint | Contact