/brlcad/tags/rel-7-14-4/src/libged/quat.c

https://bitbucket.org/vrrm/brl-cad-copy-for-fast-history-browsing-in-git · C · 86 lines · 36 code · 14 blank · 36 comment · 9 complexity · 781717f128552ff00a49e71e486fc33e MD5 · raw file

  1. /* Q U A T . C
  2. * BRL-CAD
  3. *
  4. * Copyright (c) 2008-2009 United States Government as represented by
  5. * the U.S. Army Research Laboratory.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public License
  9. * version 2.1 as published by the Free Software Foundation.
  10. *
  11. * This library is distributed in the hope that it will be useful, but
  12. * WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public
  17. * License along with this file; see the file named COPYING for more
  18. * information.
  19. */
  20. /** @file quat.c
  21. *
  22. * The quat command.
  23. *
  24. */
  25. #include "common.h"
  26. #include <stdlib.h>
  27. #include <ctype.h>
  28. #include <string.h>
  29. #include "bio.h"
  30. #include "./ged_private.h"
  31. int
  32. ged_quat(struct ged *gedp, int argc, const char *argv[])
  33. {
  34. quat_t quat;
  35. static const char *usage = "a b c d";
  36. GED_CHECK_DATABASE_OPEN(gedp, BRLCAD_ERROR);
  37. GED_CHECK_VIEW(gedp, BRLCAD_ERROR);
  38. GED_CHECK_ARGC_GT_0(gedp, argc, BRLCAD_ERROR);
  39. /* initialize result */
  40. bu_vls_trunc(&gedp->ged_result_str, 0);
  41. /* return Viewrot as a quaternion */
  42. if (argc == 1) {
  43. quat_mat2quat(quat, gedp->ged_gvp->gv_rotation);
  44. bu_vls_printf(&gedp->ged_result_str, "%.12g %.12g %.12g %.12g", V4ARGS(quat));
  45. return BRLCAD_OK;
  46. }
  47. if (argc != 6) {
  48. bu_vls_printf(&gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
  49. return BRLCAD_ERROR;
  50. }
  51. /* Set the view orientation given a quaternion */
  52. if (sscanf(argv[2], "%lf", quat) != 1 ||
  53. sscanf(argv[3], "%lf", quat+1) != 1 ||
  54. sscanf(argv[4], "%lf", quat+2) != 1 ||
  55. sscanf(argv[5], "%lf", quat+3) != 1) {
  56. bu_vls_printf(&gedp->ged_result_str, "%s quat: bad value detected - %s %s %s %s",
  57. argv[0], argv[2], argv[3], argv[4], argv[5]);
  58. return BRLCAD_ERROR;
  59. }
  60. quat_quat2mat(gedp->ged_gvp->gv_rotation, quat);
  61. ged_view_update(gedp->ged_gvp);
  62. return BRLCAD_OK;
  63. }
  64. /*
  65. * Local Variables:
  66. * tab-width: 8
  67. * mode: C
  68. * indent-tabs-mode: t
  69. * c-file-style: "stroustrup"
  70. * End:
  71. * ex: shiftwidth=4 tabstop=8
  72. */